일정 갯수의 파드를 유지하는 컨트롤러
cat << EOF >replicaset-cndk.yaml
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: replicaset-cndk
spec:
replicas: 3
selector:
matchLabels:
app: cndk-nginx-pods
template:
metadata:
name: cndk-nginx-pod
labels:
app: cndk-nginx-pods
spec:
containers:
- name: nginx
image: nginx:latest
EOF
[root@master aiden (⎈ |kube:default)]# kubectl apply -f replicaset-cndk.yaml
replicaset.apps/replicaset-cndk created
[root@master aiden (⎈ |kube:default)]# kubectl describe replicasets.apps replicaset-cndk
Name: replicaset-cndk
Namespace: default
Selector: app=cndk-nginx-pods
Labels: <none>
Annotations: <none>
Replicas: 3 current / 3 desired
Pods Status: 3 Running / 0 Waiting / 0 Succeeded / 0 Failed
Pod Template:
Labels: app=cndk-nginx-pods
Containers:
nginx:
Image: nginx:latest
Port: <none>
Host Port: <none>
Environment: <none>
Mounts: <none>
Volumes: <none>
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal SuccessfulCreate 2m1s replicaset-controller Created pod: replicaset-cndk-wxwl8
Normal SuccessfulCreate 2m1s replicaset-controller Created pod: replicaset-cndk-h6nxz
Normal SuccessfulCreate 2m1s replicaset-controller Created pod: replicaset-cndk-x45pv
[root@master aiden (⎈ |kube:default)]# kubectl get replicasets.apps -o wide
NAME DESIRED CURRENT READY AGE CONTAINERS IMAGES SELECTOR
replicaset-cndk 3 3 3 2m31s nginx nginx:latest app=cndk-nginx-pods
[root@master aiden (⎈ |kube:default)]# kubectl get pod --show-labels
NAME READY STATUS RESTARTS AGE LABELS
replicaset-cndk-h6nxz 1/1 Running 0 3m20s app=cndk-nginx-pods
replicaset-cndk-wxwl8 1/1 Running 0 3m20s app=cndk-nginx-pods
replicaset-cndk-x45pv 1/1 Running 0 3m20s app=cndk-nginx-pods
[root@master aiden (⎈ |kube:default)]# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
replicaset-cndk-h6nxz 1/1 Running 0 3m25s 172.16.189.69 worker2 <none> <none>
replicaset-cndk-wxwl8 1/1 Running 0 3m25s 172.16.235.152 worker1 <none> <none>
replicaset-cndk-x45pv 1/1 Running 0 3m25s 172.16.182.3 worker3 <none> <none>
[root@master aiden (⎈ |kube:default)]# kubectl edit replicasets.apps replicaset-cndk
... 생략 ...
spec:
replicas: 6 # 기존의 3을 6으로 변경
... 생략 ...
:wq # 저장
replicaset.apps/replicaset-cndk edited
[root@master aiden (⎈ |kube:default)]# kubectl get pods
NAME READY STATUS RESTARTS AGE
replicaset-cndk-gd2d8 1/1 Running 0 90s
replicaset-cndk-h6nxz 1/1 Running 0 5m40s
replicaset-cndk-jfhqg 1/1 Running 0 90s
replicaset-cndk-tjv45 1/1 Running 0 90s
replicaset-cndk-wxwl8 1/1 Running 0 5m40s
replicaset-cndk-x45pv 1/1 Running 0 5m40s
[root@master aiden (⎈ |kube:default)]# kubectl delete replicasets.apps replicaset-cndk
replicaset.apps "replicaset-cndk" deleted
[root@master aiden (⎈ |kube:default)]# kubectl get pods
No resources found in default namespace.
[root@master aiden (⎈ |kube:default)]# kubectl apply -f replicaset-cndk.yaml
replicaset.apps/replicaset-cndk created
[root@master aiden (⎈ |kube:default)]# kubectl get replicasets.apps -o wide
NAME DESIRED CURRENT READY AGE CONTAINERS IMAGES SELECTOR
replicaset-cndk 3 3 3 30s nginx nginx:latest app=cndk-nginx-pods
cat << EOF > pod-rs.yaml
apiVersion: v1
kind: Pod
metadata:
name: pod1
labels:
app: cndk-nginx-pods
spec:
containers:
- name: hello1
image: gcr.io/google-samples/hello-app:1.0
---
apiVersion: v1
kind: Pod
metadata:
name: pod2
labels:
app: cndk-nginx-pods
spec:
containers:
- name: hello2
image: gcr.io/google-samples/hello-app:2.0
EOF
[root@master aiden (⎈ |kube:default)]# kubectl apply -f pod-rs.yaml && kubectl get pod -w
pod/pod1 created
pod/pod2 created
NAME READY STATUS RESTARTS AGE
pod1 0/1 Terminating 0 0s
pod2 0/1 Terminating 0 0s
replicaset-cndk-9ljwt 1/1 Running 0 2m48s
replicaset-cndk-cnnff 1/1 Running 0 2m48s
replicaset-cndk-fnltr 1/1 Running 0 2m48s
pod1 0/1 Terminating 0 2s
pod1 0/1 Terminating 0 2s
pod2 0/1 Terminating 0 11s
pod2 0/1 Terminating 0 11s
⇒ 생성 되자마자 삭제된다
[root@master aiden (⎈ |kube:default)]# kubectl delete pod -l app=cndk-nginx-pods
pod "replicaset-cndk-cnnff" deleted
pod "replicaset-cndk-fnltr" deleted
pod "replicaset-cndk-txgkj" deleted
NAME READY STATUS RESTARTS AGE
replicaset-cndk-cnnff 0/1 Terminating 0 8m37s
replicaset-cndk-fnltr 0/1 Terminating 0 8m37s
replicaset-cndk-mjtgz 1/1 Running 0 6s
replicaset-cndk-nzjst 0/1 ContainerCreating 0 6s
replicaset-cndk-txgkj 0/1 Terminating 0 3m10s
replicaset-cndk-z2n4f 1/1 Running 0 6s
⇒ 레플리카셋의 Desired state에 따라 3개의 Pod가 삭제되어도 바로 3개가 재생성된다
[root@master aiden (⎈ |kube:default)]# kubectl get pod --show-labels
NAME READY STATUS RESTARTS AGE LABELS
replicaset-cndk-9ljwt 1/1 Running 0 4m46s app=cndk-nginx-pods
replicaset-cndk-cnnff 1/1 Running 0 4m46s app=cndk-nginx-pods
replicaset-cndk-fnltr 1/1 Running 0 4m46s app=cndk-nginx-pods
[root@master aiden (⎈ |kube:default)]# kubectl label pod replicaset-cndk-9ljwt app-
pod/replicaset-cndk-9ljwt labeled
[root@master aiden (⎈ |kube:default)]# kubectl get pod --show-labels
NAME READY STATUS RESTARTS AGE LABELS
replicaset-cndk-9ljwt 1/1 Running 0 5m56s <none>
replicaset-cndk-cnnff 1/1 Running 0 5m56s app=cndk-nginx-pods
replicaset-cndk-fnltr 1/1 Running 0 5m56s app=cndk-nginx-pods
replicaset-cndk-txgkj 1/1 Running 0 29s app=cndk-nginx-pods
⇒ 레이블을 제거한 Pod는 레플리카셋의 통제에서 벗어난다. 장애시 분석을 위한 용도로 활용.
레플리카셋의 상위 오브젝트이며, 애플리케이션 업데이트(롤링 업데이트) 및 배포 기능(롤백)을 제공
cat << EOF > deployment-cndk.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: deployment-cndk
spec:
replicas: 3
selector:
matchLabels:
app: cndk-nginx-pods
template:
metadata:
name: cndk-nginx-pod
labels:
app: cndk-nginx-pods
spec:
containers:
- name: nginx
image: nginx:latest
EOF
[root@master aiden (⎈ |kube:default)]# kubectl apply -f deployment-cndk.yaml
deployment.apps/deployment-cndk created
[root@master aiden (⎈ |kube:default)]# kubectl get deploy,rs,pods
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/deployment-cndk 3/3 3 3 31s
NAME DESIRED CURRENT READY AGE
replicaset.apps/deployment-cndk-5f5d7bfcb8 3 3 3 31s
NAME READY STATUS RESTARTS AGE
pod/deployment-cndk-5f5d7bfcb8-dlbfc 1/1 Running 0 31s
pod/deployment-cndk-5f5d7bfcb8-fd54n 1/1 Running 0 31s
pod/deployment-cndk-5f5d7bfcb8-w9j4w 1/1 Running 0 31s
[root@master aiden (⎈ |kube:default)]# kubectl get deployments.apps -o wide
NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
deployment-cndk 3/3 3 3 60s nginx nginx:latest app=cndk-nginx-pods
[root@master aiden (⎈ |kube:default)]# kubectl scale deployment --replicas=6 deployment-cndk
deployment.apps/deployment-cndk scaled
[root@master aiden (⎈ |kube:default)]# kubectl get deploy,rs,pods
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/deployment-cndk 6/6 6 6 4m12s
NAME DESIRED CURRENT READY AGE
replicaset.apps/deployment-cndk-5f5d7bfcb8 6 6 6 4m12s
NAME READY STATUS RESTARTS AGE
pod/deployment-cndk-5f5d7bfcb8-dlbfc 1/1 Running 0 4m12s
pod/deployment-cndk-5f5d7bfcb8-fd54n 1/1 Running 0 4m12s
pod/deployment-cndk-5f5d7bfcb8-mvn5j 1/1 Running 0 89s
pod/deployment-cndk-5f5d7bfcb8-pfw75 1/1 Running 0 89s
pod/deployment-cndk-5f5d7bfcb8-ss2dk 1/1 Running 0 89s
pod/deployment-cndk-5f5d7bfcb8-w9j4w 1/1 Running 0 4m12s
[root@master aiden (⎈ |kube:default)]# kubectl delete pod --all
pod "deployment-cndk-5f5d7bfcb8-dlbfc" deleted
pod "deployment-cndk-5f5d7bfcb8-fd54n" deleted
pod "deployment-cndk-5f5d7bfcb8-mvn5j" deleted
pod "deployment-cndk-5f5d7bfcb8-pfw75" deleted
pod "deployment-cndk-5f5d7bfcb8-ss2dk" deleted
pod "deployment-cndk-5f5d7bfcb8-w9j4w" deleted
NAME READY STATUS RESTARTS AGE
deployment-cndk-5f5d7bfcb8-4kj52 1/1 Running 0 12s
deployment-cndk-5f5d7bfcb8-cc5rx 1/1 Running 0 12s
deployment-cndk-5f5d7bfcb8-dlbfc 0/1 Terminating 0 4m59s
deployment-cndk-5f5d7bfcb8-mvn5j 0/1 Terminating 0 2m16s
deployment-cndk-5f5d7bfcb8-rnht9 1/1 Running 0 12s
deployment-cndk-5f5d7bfcb8-v8hsp 1/1 Running 0 12s
deployment-cndk-5f5d7bfcb8-vzbff 1/1 Running 0 12s
deployment-cndk-5f5d7bfcb8-x26bk 1/1 Running 0 12s
⇒ 6개 삭제 후 6개 재생성
[root@master aiden (⎈ |kube:default)]# kubectl delete replicasets.apps --all
replicaset.apps "deployment-cndk-5f5d7bfcb8" deleted
[root@master aiden (⎈ |kube:default)]# kubectl get deploy,rs,pods
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/deployment-cndk 6/6 6 6 6m32s
NAME DESIRED CURRENT READY AGE
replicaset.apps/deployment-cndk-5f5d7bfcb8 6 6 6 31s
NAME READY STATUS RESTARTS AGE
pod/deployment-cndk-5f5d7bfcb8-2cq54 1/1 Running 0 31s
pod/deployment-cndk-5f5d7bfcb8-j2flb 1/1 Running 0 31s
pod/deployment-cndk-5f5d7bfcb8-n5pjk 1/1 Running 0 31s
pod/deployment-cndk-5f5d7bfcb8-n68bj 1/1 Running 0 31s
pod/deployment-cndk-5f5d7bfcb8-p9mpr 1/1 Running 0 31s
pod/deployment-cndk-5f5d7bfcb8-phcvb 1/1 Running 0 31s
⇒ 레플리카셋 삭제에 따라 Pod들도 함께 삭제되지만, 디플로이먼트의 상태로 인해 레플리카셋 및 파드 재생성
[root@master aiden (⎈ |kube:default)]# kubectl delete deployments.apps deployment-cndk
deployment.apps "deployment-cndk" deleted
[root@master aiden (⎈ |kube:default)]# kubectl get deploy,rs,pods
No resources found in default namespace.
cat << EOF > deployment-nginx-1.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: deployment-nginx
spec:
replicas: 3
selector:
matchLabels:
app: cndk-nginx-pods
template:
metadata:
name: cndk-nginx-pod
labels:
app: cndk-nginx-pods
spec:
containers:
- name: nginx
image: nginx:1.11
apiVersion: apps/v1
kind: Deployment
metadata:
name: deployment-nginx
spec:
replicas: 3
selector:
matchLabels:
app: cndk-nginx-pods
template:
metadata:
name: cndk-nginx-pod
labels:
app: cndk-nginx-pods
spec:
containers:
- name: nginx
image: nginx:1.11
EOF
[root@master aiden (⎈ |kube:default)]# kubectl apply -f deployment-nginx-1.yaml --record
deployment.apps/deployment-nginx created
[root@master aiden (⎈ |kube:default)]# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
deployment-nginx-77b4cbf48d-576cr 1/1 Running 0 41s 172.16.189.84 worker2 <none> <none>
deployment-nginx-77b4cbf48d-5c5hg 1/1 Running 0 41s 172.16.182.17 worker3 <none> <none>
deployment-nginx-77b4cbf48d-lpp7g 1/1 Running 0 41s 172.16.235.169 worker1 <none> <none>
[root@master aiden (⎈ |kube:default)]# kubectl get pod -o yaml | grep "image: nginx" - image: nginx:1.11
image: nginx:1.11
- image: nginx:1.11
image: nginx:1.11
- image: nginx:1.11
image: nginx:1.11
[root@master aiden (⎈ |kube:default)]# kubectl rollout history deployment deployment-nginx
deployment.apps/deployment-nginx
REVISION CHANGE-CAUSE
1 kubectl apply --filename=deployment-nginx-1.yaml --record=true
while true; do kubectl rollout status deployment deployment-nginx && echo "--------------" && date; sleep 1; done
[root@master aiden (⎈ |kube:default)]# kubectl set image deployment deployment-nginx nginx=nginx:1.12 --record && kubectl get pod -w
deployment.apps/deployment-nginx image updated
NAME READY STATUS RESTARTS AGE
deployment-nginx-77b4cbf48d-576cr 1/1 Running 0 3m20s
deployment-nginx-77b4cbf48d-5c5hg 1/1 Running 0 3m20s
deployment-nginx-77b4cbf48d-lpp7g 1/1 Running 0 3m20s
deployment-nginx-78bc6dfdf7-xmh8v 0/1 ContainerCreating 0 0s
deployment-nginx-78bc6dfdf7-xmh8v 0/1 ContainerCreating 0 0s
deployment-nginx-78bc6dfdf7-xmh8v 1/1 Running 0 10s
deployment-nginx-77b4cbf48d-lpp7g 1/1 Terminating 0 3m30s
deployment-nginx-78bc6dfdf7-wzdxj 0/1 Pending 0 0s
deployment-nginx-78bc6dfdf7-wzdxj 0/1 Pending 0 0s
deployment-nginx-78bc6dfdf7-wzdxj 0/1 ContainerCreating 0 0s
deployment-nginx-77b4cbf48d-lpp7g 1/1 Terminating 0 3m30s
deployment-nginx-78bc6dfdf7-wzdxj 0/1 ContainerCreating 0 1s
deployment-nginx-77b4cbf48d-lpp7g 0/1 Terminating 0 3m31s
deployment-nginx-77b4cbf48d-lpp7g 0/1 Terminating 0 3m34s
deployment-nginx-77b4cbf48d-lpp7g 0/1 Terminating 0 3m34s
deployment-nginx-78bc6dfdf7-wzdxj 1/1 Running 0 11s
deployment-nginx-77b4cbf48d-5c5hg 1/1 Terminating 0 3m41s
deployment-nginx-78bc6dfdf7-xpktr 0/1 Pending 0 0s
deployment-nginx-78bc6dfdf7-xpktr 0/1 Pending 0 0s
deployment-nginx-78bc6dfdf7-xpktr 0/1 ContainerCreating 0 0s
deployment-nginx-77b4cbf48d-5c5hg 1/1 Terminating 0 3m41s
deployment-nginx-78bc6dfdf7-xpktr 0/1 ContainerCreating 0 1s
deployment-nginx-77b4cbf48d-5c5hg 0/1 Terminating 0 3m42s
deployment-nginx-78bc6dfdf7-xpktr 1/1 Running 0 1s
deployment-nginx-77b4cbf48d-576cr 1/1 Terminating 0 3m42s
deployment-nginx-77b4cbf48d-576cr 1/1 Terminating 0 3m43s
deployment-nginx-77b4cbf48d-576cr 0/1 Terminating 0 3m43s
deployment-nginx-77b4cbf48d-5c5hg 0/1 Terminating 0 3m49s
deployment-nginx-77b4cbf48d-5c5hg 0/1 Terminating 0 3m49s
deployment-nginx-77b4cbf48d-576cr 0/1 Terminating 0 3m53s
deployment-nginx-77b4cbf48d-576cr 0/1 Terminating 0 3m53s
Sun 27 Jun 2021 01:10:05 PM UTC
Waiting for deployment "deployment-nginx" rollout to finish: 1 out of 3 new replicas have been updated...
Waiting for deployment "deployment-nginx" rollout to finish: 1 out of 3 new replicas have been updated...
Waiting for deployment "deployment-nginx" rollout to finish: 1 out of 3 new replicas have been updated...
Waiting for deployment "deployment-nginx" rollout to finish: 2 out of 3 new replicas have been updated...
Waiting for deployment "deployment-nginx" rollout to finish: 2 out of 3 new replicas have been updated...
Waiting for deployment "deployment-nginx" rollout to finish: 2 out of 3 new replicas have been updated...
Waiting for deployment "deployment-nginx" rollout to finish: 1 old replicas are pending termination...
Waiting for deployment "deployment-nginx" rollout to finish: 1 old replicas are pending termination...
deployment "deployment-nginx" successfully rolled out
[root@master aiden (⎈ |kube:default)]# kubectl rollout history deployment deployment-nginx
deployment.apps/deployment-nginx
REVISION CHANGE-CAUSE
1 kubectl apply --filename=deployment-nginx-1.yaml --record=true
2 kubectl set image deployment deployment-nginx nginx=nginx:1.12 --record=true
[root@master aiden (⎈ |kube:default)]# kubectl rollout undo deployment deployment-nginx --to-revision=1
deployment.apps/deployment-nginx rolled back
[root@master aiden (⎈ |kube:default)]# kubectl get replicasets.apps --show-labels
NAME DESIRED CURRENT READY AGE LABELS
deployment-nginx-77b4cbf48d 3 3 3 10m app=cndk-nginx-pods,pod-template-hash=77b4cbf48d
deployment-nginx-78bc6dfdf7 0 0 0 6m46s app=cndk-nginx-pods,pod-template-hash=78bc6dfdf7
[root@master aiden (⎈ |kube:default)]# kubectl rollout history deployment deployment-nginxdeployment.apps/deployment-nginx
REVISION CHANGE-CAUSE
2 kubectl set image deployment deployment-nginx nginx=nginx:1.12 --record=true
3 kubectl apply --filename=deployment-nginx-1.yaml --record=true
[root@master aiden (⎈ |kube:default)]# kubectl delete deployments.apps --all
deployment.apps "deployment-nginx" deleted
데몬셋(DaemonSets)은 쿠버네티스의 모든 노드에 동일한 파드를 하나씩 생성하는 오브젝트이다
로깅, 모니터링, 네트워킹 등을 위한 에이전트를 각 노드에 생성해야 할 때 유용하게 사용할 수 있다
[root@master aiden (⎈ |kube:default)]# kubectl get daemonsets.apps -n kube-system
NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE
calico-node 4 4 4 4 4 kubernetes.io/os=linux 11d
kube-proxy 4 4 4 4 4 kubernetes.io/os=linux 11d
kubectl describe daemonsets.apps -n kube-system calico-node
kubectl describe daemonsets.apps -n kube-system kube-proxy
cat << EOF > daemonset-1.yaml
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: daemonset-1
spec:
selector:
matchLabels:
name: daemonset-cndk
template:
metadata:
labels:
name: daemonset-cndk
spec:
containers:
- name: daemonset-pod
image: nginx
EOF
watch -d 'kubectl get pods,ds -o wide'
[root@master aiden (⎈ |kube:default)]# kubectl apply -f daemonset-1.yaml
daemonset.apps/daemonset-1 created
[root@master aiden (⎈ |kube:default)]# kubectl get ds -o wide
NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE CONTAINERS IMAGES SELECTOR
daemonset-1 3 3 3 3 3 <none> 21s daemonset-pod nginx name=daemonset-cndk
[root@master aiden (⎈ |kube:default)]# kubectl get pod --show-labels
NAME READY STATUS RESTARTS AGE LABELS
daemonset-1-h7nln 1/1 Running 0 26s controller-revision-hash=88d8d4645,name=daemonset-cndk,pod-template-generation=1
daemonset-1-lzpxw 1/1 Running 0 26s controller-revision-hash=88d8d4645,name=daemonset-cndk,pod-template-generation=1
daemonset-1-qll8p 1/1 Running 0 26s controller-revision-hash=88d8d4645,name=daemonset-cndk,pod-template-generation=1
[root@master aiden (⎈ |kube:default)]# kubectl describe ds daemonset-1
Name: daemonset-1
Selector: name=daemonset-cndk
... 생략 ...
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal SuccessfulCreate 31s daemonset-controller Created pod: daemonset-1-lzpxw
Normal SuccessfulCreate 31s daemonset-controller Created pod: daemonset-1-qll8p
Normal SuccessfulCreate 31s daemonset-controller Created pod: daemonset-1-h7nln
[root@master aiden (⎈ |[root@master aiden (⎈ |kube:default)]# kubectl delete pod --allpod "daemonset-1-h7nln" deleted
pod "daemonset-1-lzpxw" deleted
Every 2.0s: kubectl get pods,ds -o wide master: Sun Jun 27 13:30:14 2021
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
pod/daemonset-1-9fzwx 1/1 Running 0 7s 172.16.189.88 worker2 <none> <none>
pod/daemonset-1-lzpxw 0/1 Terminating 0 2m38s <none> worker1 <none> <none>
pod/daemonset-1-qll8p 0/1 Terminating 0 2m38s 172.16.182.20 worker3 <none> <none>
NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE CONTAINERS IMAGES SELECTOR
daemonset.apps/daemonset-1 3 3 1 3 1 <none> 2m38s daemonset-pod nginx name=daemonset-cndk
Every 2.0s: kubectl get pods,ds -o wide master: Sun Jun 27 13:30:36 2021
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
pod/daemonset-1-9fzwx 1/1 Running 0 29s 172.16.189.88 worker2 <none> <none>
pod/daemonset-1-q8zs8 1/1 Running 0 16s 172.16.235.173 worker1 <none> <none>
pod/daemonset-1-sbgxt 1/1 Running 0 21s 172.16.182.21 worker3 <none> <none>
NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE CONTAINERS IMAGES SELECTOR
daemonset.apps/daemonset-1 3 3 3 3 3 <none> 3m daemonset-pod nginx name=daemonset-cndk
[root@master aiden (⎈ |kube:default)]# kubectl delete ds daemonset-1
daemonset.apps "daemonset-1" deleted
cat << EOF > daemonset-2.yaml
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: daemonset-2
spec:
selector:
matchLabels:
name: daemonset-cndk-2
template:
metadata:
labels:
name: daemonset-cndk-2
spec:
tolerations:
- effect: NoSchedule
operator: Exists
containers:
- name: daemonset-pod-2
image: nginx
EOF
[root@master aiden (⎈ |kube:default)]# kubectl apply -f daemonset-2.yaml
daemonset.apps/daemonset-2 created
[root@master aiden (⎈ |kube:default)]# kubectl get ds -o wide
NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE CONTAINERS IMAGES SELECTOR
daemonset-2 4 4 4 4 4 <none> 19s daemonset-pod-2 nginx name=daemonset-cndk-2
[root@master aiden (⎈ |kube:default)]# kubectl get pod --show-labels
NAME READY STATUS RESTARTS AGE LABELS
daemonset-2-g4q6m 1/1 Running 0 25s controller-revision-hash=8bc7c45d6,name=daemonset-cndk-2,pod-template-generation=1
daemonset-2-k2kw9 1/1 Running 0 25s controller-revision-hash=8bc7c45d6,name=daemonset-cndk-2,pod-template-generation=1
daemonset-2-qcw52 1/1 Running 0 25s controller-revision-hash=8bc7c45d6,name=daemonset-cndk-2,pod-template-generation=1
daemonset-2-zj4nf 1/1 Running 0 25s controller-revision-hash=8bc7c45d6,name=daemonset-cndk-2,pod-template-generation=1
잡(Job)은 특정 동작을 수행하고 종료해야 하는 작업을 위한 오브젝트이다 (파드가 실행되어 정상적으로 종료되는 것)
cat << EOF > job.yaml
apiVersion: batch/v1
kind: Job
metadata:
name: pi
spec:
template:
spec:
containers:
- name: pi
image: perl
command: ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"]
restartPolicy: Never
backoffLimit: 4
EOF
watch -d 'kubectl get pods,jobs -o wide'
[root@master aiden (⎈ |kube:default)]# kubectl apply -f job.yaml && kubectl get pods -w
job.batch/pi created
NAME READY STATUS RESTARTS AGE
pi-z2cxv 0/1 ContainerCreating 0 0s
pi-z2cxv 0/1 ContainerCreating 0 1s
pi-z2cxv 1/1 Running 0 4s
pi-z2cxv 0/1 Completed 0 9s
pi-z2cxv 0/1 Completed 0 9s
[root@master aiden (⎈ |kube:default)]# kubectl get jobs.batch pi -o wide
NAME COMPLETIONS DURATION AGE CONTAINERS IMAGES SELECTOR
pi 1/1 9s 31s pi perl controller-uid=611b632c-4202-4503-af49-df6ddf780d25
[root@master aiden (⎈ |kube:default)]# kubectl describe jobs.batch pi
Name: pi
Namespace: default
Selector: controller-uid=611b632c-4202-4503-af49-df6ddf780d25
Labels: controller-uid=611b632c-4202-4503-af49-df6ddf780d25
job-name=pi
... 생략 ...
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal SuccessfulCreate 44s job-controller Created pod: pi-z2cxv
Normal Completed 35s job-controller Job completed
cat << EOF > cronjob.yaml
apiVersion: batch/v1
kind: CronJob
metadata:
name: hello
spec:
schedule: "*/1 * * * *" # Job 실행 주기
successfulJobsHistoryLimit: 10 # 성공 Job 최대 기록
jobTemplate: # 실행될 Job 설정 내용(spec)
spec:
template:
spec:
containers:
- name: hello
image: busybox
imagePullPolicy: IfNotPresent
command:
- /bin/sh
- -c
- date; echo Hello from the DKOS Member!
restartPolicy: OnFailure
EOF
watch -d 'kubectl get pods,cronjobs -o wide'
[root@master aiden (⎈ |kube:default)]# kubectl apply -f cronjob.yaml && kubectl get jobs --watch
cronjob.batch/hello created
NAME COMPLETIONS DURATION AGE
hello-27080027 0/1 0s
hello-27080027 0/1 0s 0s
hello-27080027 1/1 2s 2s
hello-27080028 0/1 0s
hello-27080028 0/1 0s 0s
hello-27080028 1/1 1s 1s
[root@master aiden (⎈ |kube:default)]# kubectl get pod
NAME READY STATUS RESTARTS AGE
hello-27080027-rd65w 0/1 Completed 0 2m23s
hello-27080028-fqbs7 0/1 Completed 0 83s
[root@master aiden (⎈ |kube:default)]# kubectl get cronjobs.batch
NAME SCHEDULE SUSPEND ACTIVE LAST SCHEDULE AGE
hello */1 * * * * False 0 59s 3m21s
[root@master aiden (⎈ |kube:default)]# kubectl get jobs.batch
NAME COMPLETIONS DURATION AGE
hello-27080027 1/1 2s 3m3s
hello-27080028 1/1 1s 2m3s
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
pod/hello-27080027-rd65w 0/1 Completed 0 82s 172.16.235.177 worker1 <none> <none>
pod/hello-27080028-fqbs7 0/1 Completed 0 22s 172.16.235.178 worker1 <none> <none>
NAME COMPLETIONS DURATION AGE CONTAINERS IMAGES SELECTOR
job.batch/hello-27080027 1/1 2s 82s hello busybox controller-uid=e7e6484f-f843-44ad-baf7-3b590e2dcfd0
job.batch/hello-27080028 1/1 1s 22s hello busybox controller-uid=fa6f3fdf-ee67-497d-94a5-08e2cff9ed59
[root@master aiden (⎈ |kube:default)]# kubectl delete -f cronjob.yaml
cronjob.batch "hello" deleted