kubernetes - deptno/deptno.github.io GitHub Wiki
- TODO: sudo kubeadm certs check-expiration
- init container
์ค์ ์ ์ํด ์ ์คํ๋๊ณ ์ข
๋ฃ๋๋ ์ปจํ
์ด๋
- https://kubernetes.io/ko/docs/concepts/workloads/pods/init-containers/ ์ฌ๋ฌ ์ปจํ ์ด๋๊ฐ ์ ์ธ๋๊ฒฝ์ฐ ์์ฐจ์ ์ผ๋ก ์คํ๋๋คgpt
- container ์ค ํ๋๋ง ์ฃฝ์ด๋ ํ๋ ๋ด์ ์ปจํ ์ด๋๋ค์ด ์ฌ์์๋๋ ๋๋ ๊ฒ์ธ์ง 503 ์ด ๋ธ
- ์ฌ์ค ํ๋ ์ค ํ๋๋ ์ด๊ธฐ ์ค์ ์ ์ํ ๊ฑฐ์๋๋ฐ ์ด๋ฅผ initContainer ๋ก ๋ง๋ค๊ณ ๋๋ ์๋ฌ๊ฐ ์๋จ
- ์ ์ ์ข ๋ฃ๋๋๋ผ๋ deployment ํน์ฑ์ ์คํ์ค์ธ container๊ฐ ์ ์ง๋์ด์ผํด์ ์ค๋ฅ๋ก ๋ณด๊ณ pod ์ฌ์์์ด ๋ ์ ์์ ๊ฒ ๊ฐ์
- ์ค์ ํ ์ข ๋ฃ๋๋ ํ๋๋ค์ initContainer ๋ก ์ฎ๊ธฐ์
๋ถ ์ ์ผ ์ ์์ผ | |
---|---|
*/2 * * * * |
๋งค 2๋ถ๋ง๋ค |
1/2 * * * * |
๋งค 2๋ถ๋ง๋ค(1๋ถ, 3๋ถ...) |
-
successfulJobsHistoryLimit: [number]
์ต์ ์ ํฌ๊ฒ ์ค์ ํ๋ฉด worker node ์ cpu, mem ์ ์ํฅ์ ๋ฏธ์น๋ค -
suspend: [boolean]
์ค์ผ์ค์ ์ ์ ๋ฉ์ถ๋ ๊ฒ์ผ๋ก ๋ณด์ด๋๋ฐ ๋ํ๋ก์ด์ํ ๋ ์ ์ฉํด ๋ณด์
StorageSlass
์ถ๊ฐ ์์ด nfs mount ๊ฐ ๊ฐ๋ฅ
AccessMode | ์ฝ์ด | node:pvc | pvc:pod | ๋น๊ณ |
---|---|---|---|---|
ReadWriteOnce | RWO | 1:1 | 1:n | |
ReadOnlyMany | ROX | n:1 | 1:n | |
ReadWriteMany | RWX | n:1 | 1:n | eg. nfs |
ReadWriteOncePod | RWOP | 1:1 | 1:1 | 1.22+ |
- ์ฝ์ด๋ cli ์์ ์ฌ์ฉ
- pv:pvc ๋ 1:1 ๊ด๊ณ
- pvc ๋ namespace ์ค๋ธ์ ํธ์์ผ๋ก pv ์ access mode ์ ๋ฌด๊ดํ๊ฒ namespace ์ ์ข ์
- ReadWriteOnce ๋ node ๊ธฐ์ค์ผ๋ก pod ๋ ํ๋์ pvc์ ์ฌ๋ฟ ๋ถ์ ์ ์์
- pvc - pod 1:n ์ด ๊ฐ๋ฅ
- pv - pvc ๋ 1:1 ReadWriteOnce ์ธ๊ฒฝ์ฐ
- local - pv ๋ n:1 ์ด ๊ฐ๋ฅ
$ kdel pvc [pvc]
persistentvolumeclaim "[pvc]" deleted
^C # ๋ฉ์ถฐ์ ๊ฐ์ ์ข
๋ฃ
$ k get volumeattachments.storage.k8s.io
No resources found # ์ฌ์ฉ ์ฃผ์ฒด๊ฐ ์๋ค
$ pvc get
$ k get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
[pvc] Terminating pvc-9d3a82a2-49bd-45e7-99b7-e68eb8b76f34 20M RWO openebs-hostpath 30h
์ญ์ ๋์ง ์๊ณ Terminating
์ํ์์ ๋ฉ์ถ๋ค
kubectl patch pvc {PVC_NAME} -p '{"metadata":{"finalizers":null}}'
์ ๋ฐฉ์์ผ๋ก ์ญ์ ๊ฐ ๊ฐ๋ฅ
- openebs ์ hostpath ์ธ ๊ฒฝ์ฐ ๋ฐ์ดํฐ๋ ์ด์ ๋จ์ผ๋ ์ฐธ๊ณ
์ด๋ pv ๋ Released
์ํ๊ฐ ๋๋ฉด ๋ค๋ฅธ pvc ์๋ ๋ฐ์ธ๋ฉํ ์ ์๋ค. pv ์ ์ํ๋ฅผ Available
๋ก ๋ฐ๊พธ๊ธฐ ์ํด์๋ pv ๋ฅผ ์์ ํ์ฌ claimRef
๋ฅผ ์ ๊ฑฐํด์ผํ๋ค
kubectl patch pv [ PV_NAME ] -p '{"spec":{"claimRef": null}}'
Warning FailedMount 24s (x7 over 56s) kubelet MountVolume.NewMounter initialization failed for volume "pv-static" : path "/var/openebs/local/some-directory" does not exist
ํด๋น ๋๋ ํ ๋ฆฌ๋ ์๋์ผ๋ก ๋ง๋ค์ด์ค๋ค
mount: /var/lib/kubelet/pods/91f95da8-3cea-4f8a-a367-c2b11b3444b5/volumes/kubernetes.io~nfs/test-volume: bad option; for several filesystems (e.g. nfs, cifs) you might need a /sbin/mount.<type> helper program. โ
- worker node ์ nfs-common ์ค์น
mount.nfs: failed to apply fstab options
- ๊ถํ ์ด์
Warning FailedScheduling 29s default-scheduler 0/1 nodes are available: 1 Too many pods. preemption: 0/1 nodes are available: 1 No
preemption victims found for incoming pod..
๋ฌดํ๋ฃจํ์ ์ํด์ cronjob ์ job ํ๋๊ฐ ์ง์์ ์ผ๋ก ์์ด๋ ๋ฌธ์ ๊ฐ ์์๋๋ฐ ํ๋๊ฐ 160๊ฐ ์ ๋๊ฐ๋๋ ๋จ์ง ๋ชปํ๋ค
- TODO: ๋ ธ๋๋น ํ๋ ๊ฐฏ์์ ๋ํด์ ์กฐ์ฌ
์ฉ๋ ๋ถ์กฑ์ด๋ค. 2TB ๋์คํฌ๋ฅผ ์ฌ์ฉ ์ค์ด์๋๋ฐ ๋์ค์ ํ์ธํด ๋ณด๋ ์ฐ๋ถํฌ ์ค์น์์ 100G ํํฐ์ ์ ์ฌ์ฉํ๊ณ ์์๋ค. ๊ทธ๋ง์ ๋ /var/openebs/local, /var/lib/kubelet/pods/... ์๋ ๋ฐ์ดํฐ๊ฐ ์ค์ฒฉ์ผ๋ก ์์ด๋ฉด์ 50G ๋ง์ ๋ฐ์ํ๋ค.
echo ๋ฅผ ์ฌ์ฉํ๋ฉด newline \n
์ด ๋ถ๊ฒ๋๋ค.
-
echo -n
์ ์ฌ์ฉ - tr -d '\n'
# ํ์ผ๋ก ๋ถํฐ ๊ฐ ์์ฑ
kubectl create secret generic [name] --from-file=[key]=[filename] --from-file=[key]=[filename]
# ์ง์ ์
๋ ฅํ ๊ฐ์ผ๋ก ๋ถํฐ ์์ฑ
kubectl create secret generic [name] --from-literal=[key]=[base64 encoded value]
# ๊ธฐ์กด ์ํฌ๋ฆฟ์ ์ถ๊ฐ ํน์ ๊ฐ ๋ณ๊ฒฝ
kubectl patch secret [name] -p '{"data": {["key"]: "[based encoded value]"}}'
# ์ํฌ๋ฆฟ ๋ค์์คํ์ด์ค ๋ณต์ฌ
kubectl get secret -n [ namespace ] [ secret name ] | kubectl neat | sed "s/namespace: .*/namespace: [ target namespace]/" | kubectl apply -f -
์ ์ ์ถ๊ฐ
์ฉ์ด์ ๋ฆฌ
์ฉ์ด | ์ค๋ช |
---|---|
CSR | Certificate Signing Request |
-
์ฃผ์
- ์ถํ RoleBinding ๊ณผ ์ด์ด์ง๋ ๋ถ๋ถ์ yaml ์์์์ ๋ด์ฉ๊ณผ๋ ์๊ด์์ด ์ธ์ฆ์ ์์ฑ์์ ์ง์ ํ๋ CN=User / O=Group ์ ๊ด๊ณ๋๋ค
- CertificateSigningRequest ์์ฑ
$ openssl genrsa -out user.key 2048
$ openssl req -new -key user.key -out user.csr
$ cat <<EOF | kubectl apply -f -
apiVersion: certificates.k8s.io/v1
kind: CertificateSigningRequest
metadata:
name: user
spec:
request: $(cat user.csr | base64)
signerName: kubernetes.io/kube-apiserver-client
expirationSeconds: 3600
usages:
- client auth
EOF
certificatesigningrequest.certificates.k8s.io/user created
template ํ ๊ด๋ จํด์๋ envsubst ์ฐธ์กฐ
- CertificateSigningRequest approve
$ k get csr
NAME AGE SIGNERNAME REQUESTOR REQUESTEDDURATION CONDITION
user 34s kubernetes.io/kube-apiserver-client kubernetes-admin 60m Pending
$ kubectl get csr user -o jsonpath='{.status.certificate}'| base64 -d > user.crt
$ kubectl config set-credentials user --client-key=user.key --client-certificate=user.crt --embed-certs
User "user" set.
$ kubectl config set-context user --cluster=local --user=user
Context "user" created.
$ kubectl config use-context user
Switched to context "user".
$ kgp
Error from server (Forbidden): pods is forbidden: User "user.dev" cannot list resource "pods" in API group "" in the namespace "default"
๊ถํ์ด ์์ด์ ๋์ง ์๋๋ค ๋ค์ ์๋์ context(๊ถํ์ด ์๋) ๋์์์ role, rolebinding ์ ์์ฑํ๋ค
- role, rolebinding ์์ฑ
$ kubectl create role test --verb=get --verb=list --resource=pods
role.rbac.authorization.k8s.io/test created
$ kubectl create rolebinding test-user --role=test --user=user
rolebinding.rbac.authorization.k8s.io/test-user created
- ๋ค์ user ๋ก ๊ถํ์ ํ์ธํ๋ค
$ k config use-context user
Switched to context "user".
$ kgp
Error from server (Forbidden): pods is forbidden: User "user.dev" cannot list resource "pods" in API group "" in the namespace "default"
$ kgp -n test
Error from server (Forbidden): pods is forbidden: User "user.dev" cannot list resource "pods" in API group "" in the namespace "test"
$ k auth can-i list pods
no
$ k auth can-i list pods -n test
no
$ k api-resources head -1 ; k api-resources | grep pod
NAME SHORTNAMES APIVERSION NAMESPACED KIND
pods po v1 true Pod
๋ถ์กฑํ ๊ฒ๋ค์ role, rolebinding ์ ๋ฃ๋๋ก ํ์
- role ์ apiGroups ์
v1
์ถ๊ฐ - rolebinding ์
namespace
์ถ๊ฐ
$ k use-context user
error: unknown command "use-context" for "kubectl"
$ kgp
NAME READY STATUS RESTARTS AGE
curl 1/1 Running 5 (10d ago) 23d
CertificateSigningRequest ํ์๊ฐ์ด ์ง๋๋ฉด ํ ํฐ์ด ๋ง๋ฃ๋์ด ๋ก๊ทธ์ธ์ด ๋์ง ์๋๋ค. approve ์์ ์ด ์๋๋ผ csr ์ ์์ฑํ ํ์์ผ๋ก๋ถํฐ ํ์๊ฐ์ด๋ค, ์์ฑ์ ๋ฃ์ด์คฌ๋ ์๋ prop์ ์ํด์ ์ ์๋๋ค
expirationSeconds: 3600
$ kgp
error: You must be logged in to the server (Unauthorized)
PEM block type must be CERTIFICATE REQUEST
CertificateSigningRequest ์์ฑ์์ ๋ฐ์ํ๋๋ฐ cat user.csr | base
ํ ๊ฐ์ด ๋ค์ด๊ฐ์ผํ๋ค
๋ก์ปฌ์์๋ minikube ๋ฅผ ์ฌ์ฉํ๋ค.
๋ฏธ๋์ฟ ๋ฒ ์์ pv ๋ local
์ ์ง์๋์ง ์์ผ๋ฉฐ hostPath ๋ง ์ง์ํ๋ค.
multipass ๋ฅผ ์ฌ์ฉํ๋ฉด vm์ ์ด์ฉํ์ฌ ์ค์ ์ ๊ฐ์ ํด๋ฌ์คํฐ ๊ตฌํ์ด ๊ฐ๋ฅํ๋ค.
error: --overwrite is false but found the following declared annotation(s):
kubectl annotate ์์ --overwrite ์ต์ ์ ์ถ๊ฐํ๊ฑฐ๋ --force๋ฅผ ์ถ๊ฐํด์ ํด๊ฒฐํ๋ค