일단 쿠버네티스 pod 만들기 (tistory.com)
deployment가 생성한 pod가 지워지지 않는 곳에서 이어서 시작할게요
그럼 이 deployment가 뭔지 살짝 자세하게 보면
kubectl describe deployments.apps mydepl
#결과
Name: mydepl
Namespace: default
CreationTimestamp: Wed, 21 Jul 2021 17:40:54 +0900
Labels: app=mydepl
Annotations: deployment.kubernetes.io/revision: 1
Selector: app=mydepl
Replicas: 1 desired | 1 updated | 1 total | 1 available | 0 unavailable
StrategyType: RollingUpdate
MinReadySeconds: 0
RollingUpdateStrategy: 25% max unavailable, 25% max surge
Pod Template:
Labels: app=mydepl
Containers:
show-me-host:
Image: xodwkx2/show-me-host:1.0.0
Port: <none>
Host Port: <none>
Environment: <none>
Mounts: <none>
Volumes: <none>
Conditions:
Type Status Reason
---- ------ ------
Progressing True NewReplicaSetAvailable
Available True MinimumReplicasAvailable
OldReplicaSets: <none>
NewReplicaSet: mydepl-c9c5699f6 (1/1 replicas created)
Events: <none>
Replicas: 1 desired | 1 updated | 1 total | 1 available | 0 unavailable
사본은 1개를 원했는데 1개가 업데이트됐고 그래서 총 1개가 있고 1개가 가능하고 0개가 불가능하다
그럼 5개를 원하면?
kubectl scale deployment mydepl --replicas=5
# 결과
deployment.apps/mydepl scaled
# 확인
kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
mydepl-c9c5699f6-5vljl 1/1 Running 0 4h36m 10.44.0.3 k8s-node1 <none> <none>
mydepl-c9c5699f6-dm8vs 1/1 Running 0 14s 10.44.0.9 k8s-node1 <none> <none>
mydepl-c9c5699f6-frqs9 0/1 ContainerCreating 0 14s <none> k8s-node3 <none> <none>
mydepl-c9c5699f6-hwzzw 1/1 Running 0 14s 10.44.0.1 k8s-node1 <none> <none>
mydepl-c9c5699f6-n9tcr 1/1 Running 0 14s 10.36.0.2 k8s-node2 <none> <none>
다시 이 deployment의 description을 보면
kubectl describe deployments.apps mydepl
# 결과
Name: mydepl
Namespace: default
CreationTimestamp: Wed, 21 Jul 2021 17:40:54 +0900
Labels: app=mydepl
Annotations: deployment.kubernetes.io/revision: 1
Selector: app=mydepl
Replicas: 5 desired | 5 updated | 5 total | 5 available | 0 unavailable
StrategyType: RollingUpdate
MinReadySeconds: 0
RollingUpdateStrategy: 25% max unavailable, 25% max surge
Pod Template:
Labels: app=mydepl
Containers:
show-me-host:
Image: xodwkx2/show-me-host:1.0.0
Port: <none>
Host Port: <none>
Environment: <none>
Mounts: <none>
Volumes: <none>
여기까지는 이해가 가고. 이 deployment가 만드는 pod들을 지우려면 아마 이 deployment부터 지워야겠네요.
kubectl delete deployments.apps mydepl
#결과
deployment.apps "mydepl" deleted
#확인
kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GAT
ES
mydepl-c9c5699f6-8zwjz 1/1 Terminating 0 4m16s 10.47.0.2 k8s-node3 <none> <none>
mydepl-c9c5699f6-cmzfv 1/1 Terminating 0 3m44s 10.36.0.2 k8s-node2 <none> <none>
mydepl-c9c5699f6-frqs9 1/1 Terminating 0 15m 10.47.0.1 k8s-node3 <none> <none>
mydepl-c9c5699f6-hwzzw 1/1 Terminating 0 16m 10.44.0.1 k8s-node1 <none> <none>
mydepl-c9c5699f6-phsw6 1/1 Terminating 0 15m 10.36.0.1 k8s-node2 <none> <none>
kubectl get pods -o wide
No resources found in default namespace.
깔끔
다시 deployment를 만들어봐요. 이번엔 시작할 때부터 사본의 개수를 5개로 정해줄게요.
kubectl create deployment mydep --image=xodwkx2/show-me-host:1.0.0 --replicas=5
#결과
deployment.apps/mydep created
#확인
kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
mydep-b7d586bf8-4b5kg 1/1 Running 0 11m 10.36.0.1 k8s-node2 <none> <none>
mydep-b7d586bf8-4z5xr 1/1 Running 0 11m 10.47.0.1 k8s-node3 <none> <none>
mydep-b7d586bf8-ft6kq 1/1 Running 0 11m 10.44.0.1 k8s-node1 <none> <none>
mydep-b7d586bf8-t2hxg 1/1 Running 0 11m 10.47.0.2 k8s-node3 <none> <none>
mydep-b7d586bf8-wvx46 1/1 Running 0 11m 10.44.0.2 k8s-node1 <none> <none>
#자세하게 확인
kubectl describe deployments.apps mydep
Name: mydep
Namespace: default
CreationTimestamp: Wed, 21 Jul 2021 23:44:51 +0900
Labels: app=mydep
Annotations: deployment.kubernetes.io/revision: 1
Selector: app=mydep
Replicas: 5 desired | 5 updated | 5 total | 5 available | 0 unavailable
StrategyType: RollingUpdate
MinReadySeconds: 0
RollingUpdateStrategy: 25% max unavailable, 25% max surge
Pod Template:
Labels: app=mydep
Containers:
show-me-host:
Image: xodwkx2/show-me-host:1.0.0
Port: <none>
Host Port: <none>
Environment: <none>
Mounts: <none>
Volumes: <none>
Conditions:
Type Status Reason
---- ------ ------
Available True MinimumReplicasAvailable
Progressing True NewReplicaSetAvailable
OldReplicaSets: <none>
NewReplicaSet: mydep-b7d586bf8 (5/5 replicas created)
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal ScalingReplicaSet 12m deployment-controller Scaled up replica set mydep-b7d586bf8 to 5
xodwkx2/show-me-host:1.0.0은 node.js를 사용해서 웹서버를 실행하고 8080 포트를 통해서 서비스하게 만들어요.
그럼 그 이미지를 사용해서 만든 pod에는 이렇게 접속할 수 있어요.
#pod IP 확인
kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
mydep-b7d586bf8-4b5kg 1/1 Running 0 13h 10.36.0.1 k8s-node2 <none> <none>
mydep-b7d586bf8-4z5xr 1/1 Running 0 13h 10.47.0.1 k8s-node3 <none> <none>
mydep-b7d586bf8-trgds 1/1 Running 0 12h 10.36.0.2 k8s-node2 <none> <none>
# 실행
curl 10.36.0.1:8080
# 결과
mydep-b7d586bf8-4b5kg
pod 이름이 출력이되네요. show-me-host는 호스티 이름을 출력하도록 만들었는데요.
확인해볼꼐요.
kubectl exec -it mydep-b7d586bf8-4b5kg -- bash
root@mydep-b7d586bf8-4b5kg:/usr/src/app#
pod이름이 hostname으로 되어있어요.
끝