<1> 레플리카셋
<2> 디플로이먼트
<1> 레플리카셋
빨간색 부분은 '레플리카셋
보라색 부분은 '포드
1
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
2
[root@test11 ~]# kubectl apply -f replicaset-cndk.yaml
replicaset.apps/replicaset-cndk created
[root@test11 ~]# k get pods
NAME READY STATUS RESTARTS AGE
replicaset-cndk-7lppm 0/1 ContainerCreating 0 4s
replicaset-cndk-fdb5r 0/1 ContainerCreating 0 4s
replicaset-cndk-jqxj5 0/1 ContainerCreating 0 4s
3
[root@test11 ~]# kubectl get pods,rs,deploy -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
pod/replicaset-cndk-7lppm 1/1 Running 0 93s 198.18.0.245 game1-nodepool-w-11gc <none> <none>
pod/replicaset-cndk-fdb5r 1/1 Running 0 93s 198.18.0.40 game1-nodepool-w-11gc <none> <none>
pod/replicaset-cndk-jqxj5 1/1 Running 0 93s 198.18.0.11 game1-nodepool-w-11gc <none> <none>
NAME DESIRED CURRENT READY AGE CONTAINERS IMAGES SELECTOR
replicaset.apps/replicaset-cndk 3 3 3 93s nginx nginx:latest app=cndk-nginx-pods
4
라벨
[root@test11 ~]# kubectl get pod --show-labels
NAME READY STATUS RESTARTS AGE LABELS
replicaset-cndk-7lppm 1/1 Running 0 2m54s app=cndk-nginx-pods
replicaset-cndk-fdb5r 1/1 Running 0 2m54s app=cndk-nginx-pods
replicaset-cndk-jqxj5 1/1 Running 0 2m54s app=cndk-nginx-pods
[root@test11 ~]# k get rs,pods
NAME DESIRED CURRENT READY AGE
replicaset.apps/replicaset-cndk 3 3 3 5h40m
NAME READY STATUS RESTARTS AGE
pod/replicaset-cndk-7lppm 1/1 Running 0 5h40m
pod/replicaset-cndk-fdb5r 1/1 Running 0 5h40m
pod/replicaset-cndk-jqxj5 1/1 Running 0 5h40m
[root@test11 ~]#
5
Pod수 증가
kubectl edit replicasets.apps replicaset-cndk
5개로
6
kubectl get pods
[root@test11 ~]# k get pods
NAME READY STATUS RESTARTS AGE
replicaset-cndk-7k4nn 0/1 ContainerCreating 0 3s
replicaset-cndk-7lppm 1/1 Running 0 5h42m
replicaset-cndk-b5fsp 0/1 ContainerCreating 0 3s
replicaset-cndk-fdb5r 1/1 Running 0 5h42m
replicaset-cndk-jqxj5 1/1 Running
7
kubectl get replicasets.apps -o wide
[root@test11 ~]# kubectl get replicasets.apps -o wide
NAME DESIRED CURRENT READY AGE CONTAINERS IMAGES SELECTOR
replicaset-cndk 5 5 5 5h42m nginx nginx:latest app=cndk-nginx-pods
8
삭제
[root@test11 ~]# k get rs
NAME DESIRED CURRENT READY AGE
replicaset-cndk 5 5 5 5h43m
[root@test11 ~]# k delete rs replicaset-cndk
replicaset.apps "replicaset-cndk" deleted
[root@test11 ~]# k get pods
No resources found in default namespace.
<2> 디플로이먼트
레플리카셋의 상위 오브젝트이며, 애플리케이션 업데이트(롤링 업데이트) 및 배포 기능(롤백)을 제공
빨간색 부분은 '레플리카셋
보라색 부분은 '포드
1
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
2
kubectl apply -f deployment-cndk.yaml
kubectl get pods,rs,deploy -o wide
[root@test11 ~]# kubectl get pods,rs,deploy -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
pod/deployment-cndk-5f5d7bfcb8-c7b55 0/1 ContainerCreating 0 2s <none> game1-nodepool-w-11gc <none> <none>
pod/deployment-cndk-5f5d7bfcb8-f6vtg 0/1 ContainerCreating 0 2s <none> game1-nodepool-w-11gc <none> <none>
pod/deployment-cndk-5f5d7bfcb8-tlrtl 0/1 ContainerCreating 0 2s <none> game1-nodepool-w-11gc <none> <none>
NAME DESIRED CURRENT READY AGE CONTAINERS IMAGES SELECTOR
replicaset.apps/deployment-cndk-5f5d7bfcb8 3 3 0 2s nginx nginx:latest app=cndk-nginx-pods,pod-template-hash=5f5d7bfcb8
NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
deployment.apps/deployment-cndk 0/3 3 0 2s nginx nginx:latest app=cndk-nginx-pods
3
# 포드 확인 : 파드의 이름 맨 뒤부분-##### 부분은 레플리카셋이 해쉬 랜덤값을 붙인것!
kubectl get pod --show-labels
[root@test11 ~]# kubectl get pod --show-labels
NAME READY STATUS RESTARTS AGE LABELS
deployment-cndk-5f5d7bfcb8-c7b55 1/1 Running 0 2m5s app=cndk-nginx-pods,pod-template-hash=5f5d7bfcb8
deployment-cndk-5f5d7bfcb8-f6vtg 1/1 Running 0 2m5s app=cndk-nginx-pods,pod-template-hash=5f5d7bfcb8
deployment-cndk-5f5d7bfcb8-tlrtl 1/1 Running 0 2m5s app=cndk-nginx-pods,pod-template-hash=5f5d7bfcb8
4
# 디플로이먼트에 관리되는 파드 갯수를 증가해보자!
kubectl scale deployment --replicas=6 deployment-cndk
[root@test11 ~]# kubectl get pod --show-labels
NAME READY STATUS RESTARTS AGE LABELS
deployment-cndk-5f5d7bfcb8-6tzwb 1/1 Running 0 8s app=cndk-nginx-pods,pod-template-hash=5f5d7bfcb8
deployment-cndk-5f5d7bfcb8-c7b55 1/1 Running 0 2m32s app=cndk-nginx-pods,pod-template-hash=5f5d7bfcb8
deployment-cndk-5f5d7bfcb8-f6vtg 1/1 Running 0 2m32s app=cndk-nginx-pods,pod-template-hash=5f5d7bfcb8
deployment-cndk-5f5d7bfcb8-tlrtl 1/1 Running 0 2m32s app=cndk-nginx-pods,pod-template-hash=5f5d7bfcb8
deployment-cndk-5f5d7bfcb8-wftvz 1/1 Running 0 8s app=cndk-nginx-pods,pod-template-hash=5f5d7bfcb8
deployment-cndk-5f5d7bfcb8-z4slq 1/1 Running 0 8s app=cndk-nginx-pods,pod-template-hash=5f5d7bfcb8
5
# 파드를 삭제해보자! >> 어떻게 동작할지 생각해보자!
kubectl delete pod --all
다시 생성됨
[root@test11 ~]# kubectl get pod --show-labels
NAME READY STATUS RESTARTS AGE LABELS
deployment-cndk-5f5d7bfcb8-52jtg 1/1 Running 0 13s app=cndk-nginx-pods,pod-template-hash=5f5d7bfcb8
deployment-cndk-5f5d7bfcb8-dbqrt 0/1 ContainerCreating 0 13s app=cndk-nginx-pods,pod-template-hash=5f5d7bfcb8
deployment-cndk-5f5d7bfcb8-gprsr 1/1 Running 0 13s app=cndk-nginx-pods,pod-template-hash=5f5d7bfcb8
deployment-cndk-5f5d7bfcb8-np8hc 1/1 Running 0 13s app=cndk-nginx-pods,pod-template-hash=5f5d7bfcb8
deployment-cndk-5f5d7bfcb8-qfllz 0/1 ContainerCreating 0 13s app=cndk-nginx-pods,pod-template-hash=5f5d7bfcb8
deployment-cndk-5f5d7bfcb8-wm7pz 1/1 Running 0 13s app=cndk-nginx-pods,pod-template-hash=5f5d7bfcb8
[root@test11 ~]#
6
# 레플리카셋을 삭제해보자! >> 다시 생성됨
kubectl delete replicasets.apps --all
[root@test11 ~]# kubectl get pod --show-labels
NAME READY STATUS RESTARTS AGE LABELS
deployment-cndk-5f5d7bfcb8-67857 1/1 Running 0 17s app=cndk-nginx-pods,pod-template-hash=5f5d7bfcb8
deployment-cndk-5f5d7bfcb8-9gftt 1/1 Running 0 17s app=cndk-nginx-pods,pod-template-hash=5f5d7bfcb8
deployment-cndk-5f5d7bfcb8-glf5h 1/1 Running 0 17s app=cndk-nginx-pods,pod-template-hash=5f5d7bfcb8
deployment-cndk-5f5d7bfcb8-h6hcb 1/1 Running 0 17s app=cndk-nginx-pods,pod-template-hash=5f5d7bfcb8
deployment-cndk-5f5d7bfcb8-k58dv 1/1 Running 0 17s app=cndk-nginx-pods,pod-template-hash=5f5d7bfcb8
deployment-cndk-5f5d7bfcb8-txx48 0/1 ContainerCreating 0 17s app=cndk-nginx-pods,pod-template-hash=5f5d7bfcb8
7
# 다음 실습을 위해 디플로이먼트 삭제
kubectl delete deployments.apps deployment-cndk
[root@test11 ~]# k delete deploy deployment-cndk
deployment.apps "deployment-cndk" deleted
[root@test11 ~]#
[root@test11 ~]#
[root@test11 ~]# kubectl get pod --show-labels
NAME READY STATUS RESTARTS AGE LABELS
deployment-cndk-5f5d7bfcb8-67857 0/1 Terminating 0 74s app=cndk-nginx-pods,pod-template-hash=5f5d7bfcb8
deployment-cndk-5f5d7bfcb8-9gftt 0/1 Terminating 0 74s app=cndk-nginx-pods,pod-template-hash=5f5d7bfcb8
deployment-cndk-5f5d7bfcb8-glf5h 0/1 Terminating 0 74s app=cndk-nginx-pods,pod-template-hash=5f5d7bfcb8
deployment-cndk-5f5d7bfcb8-h6hcb 0/1 Terminating 0 74s app=cndk-nginx-pods,pod-template-hash=5f5d7bfcb8
deployment-cndk-5f5d7bfcb8-k58dv 0/1 Terminating 0 74s app=cndk-nginx-pods,pod-template-hash=5f5d7bfcb8
deployment-cndk-5f5d7bfcb8-txx48 0/1 Terminating 0 74s app=cndk-nginx-pods,pod-template-hash=5f5d7bfcb8
[root@test11 ~]# kubectl get pod --show-labels
No resources found in default namespace.
다음 과정
https://brunch.co.kr/@topasvga/2237
https://brunch.co.kr/@topasvga/2240
감사합니다.