728x90
쿠버네티스 디플로이먼트(kubernetes deployment)
디플로이먼트(Deployment) 는 파드와 레플리카셋(ReplicaSet)에 대한 선언적 업데이트를 제공한다.
디플로이먼트에서 의도하는 상태 를 설명하고, 디플로이먼트 컨트롤러(Controller)는 현재 상태에서 의도하는 상태로 비율을 조정하며 변경한다. 새 레플리카셋을 생성하는 디플로이먼트를 정의하거나 기존 디플로이먼트를 제거하고, 모든 리소스를 새 디플로이먼트에 적용할 수 있다.
디플로이먼트 생성(kubectl create deployment)
kubectl create deployment myapp --image=nginx
$ kubectl create deployment myapp --image=nginx
deployment.apps/myapp created
리소스 확인(kubectl get)
kubectl get deployments,replicasets,pods
$ kubectl get deployments,replicasets,pods
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/myapp 1/1 1 1 2m48s
NAME DESIRED CURRENT READY AGE
replicaset.apps/myapp-dc8dc9c59 1 1 1 2m48s
NAME READY STATUS RESTARTS AGE
pod/myapp-dc8dc9c59-jvvwx 1/1 Running 0 2m48s
$ kubectl get deployments,replicasets,pods -o wide
NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
deployment.apps/myapp 1/1 1 1 4m14s nginx nginx app=myapp
NAME DESIRED CURRENT READY AGE CONTAINERS IMAGES SELECTOR
replicaset.apps/myapp-dc8dc9c59 1 1 1 4m14s nginx nginx app=myapp,pod-template-hash=dc8dc9c59
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
pod/myapp-dc8dc9c59-jvvwx 1/1 Running 0 4m14s 10.233.118.67 kube-node3 <none> <none>
curl 테스트(pods ip)
$ curl -I 10.233.118.67
HTTP/1.1 200 OK
Server: nginx/1.23.1
Date: Sat, 01 Oct 2022 09:18:17 GMT
Content-Type: text/html
Content-Length: 615
Last-Modified: Tue, 19 Jul 2022 14:05:27 GMT
Connection: keep-alive
ETag: "62d6ba27-267"
Accept-Ranges: bytes
서비스 생성(kubectl expose deployment)
kubectl expose deployment myapp --port=80 --protocol TCP --target-port 80 --name myapp-svc --type LoadBalancer
$ kubectl expose deployment myapp --port=80 --protocol TCP --target-port 80 --name myapp-svc --type LoadBalancer
service/myapp-svc exposed
리소스 확인(kubectl get)
kubectl get deployments,replicasets,pods,service -o wide
$ kubectl get deployments,replicasets,pods,service -o wide
NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
deployment.apps/myapp 1/1 1 1 9m31s nginx nginx app=myapp
NAME DESIRED CURRENT READY AGE CONTAINERS IMAGES SELECTOR
replicaset.apps/myapp-dc8dc9c59 1 1 1 9m31s nginx nginx app=myapp,pod-template-hash=dc8dc9c59
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
pod/myapp-dc8dc9c59-jvvwx 1/1 Running 0 9m31s 10.233.118.67 kube-node3 <none> <none>
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
service/kubernetes ClusterIP 10.233.0.1 <none> 443/TCP 168m <none>
service/myapp-svc LoadBalancer 10.233.5.179 192.168.56.200 80:30811/TCP 5s app=myapp
kubectl get service -o wide
$ kubectl get service myapp-svc -o wide
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
myapp-svc LoadBalancer 10.233.5.179 192.168.56.200 80:30811/TCP 81s app=myapp
curl 테스트(loadbalancer ip)
$ curl -I 192.168.56.200
HTTP/1.1 200 OK
Server: nginx/1.23.1
Date: Sat, 01 Oct 2022 09:23:21 GMT
Content-Type: text/html
Content-Length: 615
Last-Modified: Tue, 19 Jul 2022 14:05:27 GMT
Connection: keep-alive
ETag: "62d6ba27-267"
Accept-Ranges: bytes
curl 테스트(nodeport)
$ kubectl get service myapp-svc -o wide
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
myapp-svc LoadBalancer 10.233.5.179 192.168.56.200 80:30811/TCP 67m app=myapp
$ kubectl get nodes -o wide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
kube-control1 Ready control-plane 3h56m v1.24.6 192.168.56.11 <none> Ubuntu 20.04.5 LTS 5.4.0-126-generic docker://20.10.17
kube-node1 Ready <none> 3h54m v1.24.6 192.168.56.21 <none> Ubuntu 20.04.5 LTS 5.4.0-126-generic docker://20.10.17
kube-node2 Ready <none> 3h54m v1.24.6 192.168.56.22 <none> Ubuntu 20.04.5 LTS 5.4.0-126-generic docker://20.10.17
kube-node3 Ready <none> 3h54m v1.24.6 192.168.56.23 <none> Ubuntu 20.04.5 LTS 5.4.0-126-generic docker://20.10.17
$ curl -I 192.168.56.21:30811
HTTP/1.1 200 OK
Server: nginx/1.23.1
Date: Sat, 01 Oct 2022 10:30:52 GMT
Content-Type: text/html
Content-Length: 615
Last-Modified: Tue, 19 Jul 2022 14:05:27 GMT
Connection: keep-alive
ETag: "62d6ba27-267"
Accept-Ranges: bytes
파드 스케일링(kubectl scale deployment)
kubectl scale deployment myapp --replicas 3
$ kubectl scale deployment myapp --replicas 3
deployment.apps/myapp scaled
파드 스케일링 확인
kubectl get deployments,replicasets,pods
$ kubectl get deployments,replicasets,pods
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/myapp 3/3 3 3 80m
NAME DESIRED CURRENT READY AGE
replicaset.apps/myapp-dc8dc9c59 3 3 3 80m
NAME READY STATUS RESTARTS AGE
pod/myapp-dc8dc9c59-jvvwx 1/1 Running 0 80m
pod/myapp-dc8dc9c59-mtn6w 1/1 Running 0 56s
pod/myapp-dc8dc9c59-shckl 1/1 Running 0 56s
kubectl get all
$ kubectl get all
NAME READY STATUS RESTARTS AGE
pod/myapp-dc8dc9c59-jvvwx 1/1 Running 0 82m
pod/myapp-dc8dc9c59-mtn6w 1/1 Running 0 2m20s
pod/myapp-dc8dc9c59-shckl 1/1 Running 0 2m20s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.233.0.1 <none> 443/TCP 4h1m
service/myapp-svc LoadBalancer 10.233.5.179 192.168.56.200 80:30811/TCP 72m
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/myapp 3/3 3 3 82m
NAME DESIRED CURRENT READY AGE
replicaset.apps/myapp-dc8dc9c59 3 3 3 82m
생성한 리소스 삭제
kubectl delete deployments,service --all
$ kubectl delete deployments,service --all
deployment.apps "myapp" deleted
service "kubernetes" deleted
service "myapp-svc" deleted
$ kubectl get all
NAME READY STATUS RESTARTS AGE
pod/myapp-dc8dc9c59-jvvwx 1/1 Terminating 0 83m
pod/myapp-dc8dc9c59-mtn6w 1/1 Terminating 0 3m52s
pod/myapp-dc8dc9c59-shckl 1/1 Terminating 0 3m52s
$ kubectl get all
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.233.0.1 <none> 443/TCP 34s
참고URL
- 쿠버네티스 문서 / 개념 / 워크로드 / 워크로드 리소스 / 디플로이먼트 : https://kubernetes.io/ko/docs/concepts/workloads/controllers/deployment/
728x90
'리눅스' 카테고리의 다른 글
쿠버네티스 네임스페이스를 생성하고 확인하고 삭제하는 방법(namespaces) (0) | 2022.10.03 |
---|---|
[kubernetes] 쿠버네티스 워크로드 - 파드(pods) (0) | 2022.10.03 |
Vim에서 YAML 파일을 편집하기 위한 설정(vi/vim 환경 설정) (0) | 2022.10.01 |
[kubernetes] kubectl config 명령 - 1 (0) | 2022.09.24 |
[draft] Kubernetes Helm 패키지 관리자 (0) | 2022.09.24 |