Exercise 3.4: Deploy A Sample Application
Deployment 생성
kubectl create deployment nginx --image=nginx
Deployment 상태 확인
kubectl get deploy
Pod가 생성되었는지 확인
kubectl get pod
생성된 NGINX Deployment 상태 상세 확인
kubectl describe deployment nginx
클러스터에 발생한 이벤트 확인
kubectl get events --sort-by='.metadata.creationTimestamp'
생성된 NGINX Deployment의 Manifest를 YAML 형식으로 출력
kubectl get deploy nginx -o yaml
생성된 NGINX Deployment의 Manifest를 YAML 형식으로 저장
kubectl get deploy nginx -o yaml > first.yaml
first.yaml
파일을 텍스트 에디터에서 열고 아래와 같이 수정하세요.creationTimestamp
,resourceVersion
,uid
를 포함하는 라인 삭제status
아래의 모든 라인 삭제 (status 포함)수정 완료 버전
apiVersion: apps/v1 kind: Deployment metadata: annotations: deployment.kubernetes.io/revision: "1" generation: 1 labels: app: nginx name: nginx namespace: default spec: progressDeadlineSeconds: 600 replicas: 1 revisionHistoryLimit: 10 selector: matchLabels: app: nginx strategy: rollingUpdate: maxSurge: 25% maxUnavailable: 25% type: RollingUpdate template: metadata: creationTimestamp: null labels: app: nginx spec: containers: - image: nginx imagePullPolicy: Always name: nginx resources: {} terminationMessagePath: /dev/termination-log terminationMessagePolicy: File dnsPolicy: ClusterFirst restartPolicy: Always schedulerName: default-scheduler securityContext: {} terminationGracePeriodSeconds: 30
NGINX Deployment 삭제
kubectl delete deploy nginx
위에서 생성한
first.yaml
파일을 이용해서 Deployment 생성kubectl apply -f first.yaml
Deployment 상태 확인
kubectl get deploy
새로 생성된 NGINX Deployment의 Manifest를 YAML 형식으로 저장
kubectl get deploy nginx -o yaml > second.yaml
두개의 YAML 파일을 비교
diff first.yaml second.yaml -y
Deployment의 resourceVersion 값 확인
kubectl get deploy nginx -o=jsonpath='{.metadata.resourceVersion}{"\n"}'
Deployment에 속하는 Pod 삭제
kubectl delete pod -l app=nginx
Deployment의 resourceVersion 값을 다시 확인
kubectl get deploy nginx -o=jsonpath='{.metadata.resourceVersion}{"\n"}'
dry-run
옵션으로 실제 리소스를 생성하지 않고 Manifest만 확인kubectl create deployment nginx --image=nginx --dry-run=client -o yaml
NGINX Deployment의 Manifest를 JSON 형식으로 출력
kubectl get deployment nginx -o json
NGINX Deployment에 서비스 생성
kubectl expose deployment/nginx
kubectl expose
명령어에 대한 도움말 보기kubectl expose -h
first.yaml
파일의spec.templates.spec.containers
부분을 아래와 같이 수정.... spec: containers: - image: nginx imagePullPolicy: Always name: nginx ports: - containerPort: 80 protocol: TCP ....
first.yaml
파일의 수정 완료 버전apiVersion: apps/v1 kind: Deployment metadata: annotations: deployment.kubernetes.io/revision: "1" generation: 1 labels: app: nginx name: nginx namespace: default spec: progressDeadlineSeconds: 600 replicas: 1 revisionHistoryLimit: 10 selector: matchLabels: app: nginx strategy: rollingUpdate: maxSurge: 25% maxUnavailable: 25% type: RollingUpdate template: metadata: creationTimestamp: null labels: app: nginx spec: containers: - image: nginx imagePullPolicy: Always name: nginx ports: - containerPort: 80 protocol: TCP resources: {} terminationMessagePath: /dev/termination-log terminationMessagePolicy: File dnsPolicy: ClusterFirst restartPolicy: Always schedulerName: default-scheduler securityContext: {} terminationGracePeriodSeconds: 30
변경사항 반영
kubectl apply -f first.yaml
Deployment와 Pod가 새로 생성됐는지 확인
kubectl get deploy,rs,pod
NGINX Deployment에 서비스 생성
kubectl expose deployment/nginx
NGINX 서비스 확인
kubectl get svc nginx
NGINX 서비스에 연결된 Endpoints 확인
kubectl get ep nginx
현재 배포된 Pod의 IP 주소 확인
kubectl get pod -l app=nginx -o wide
Worker 노드에 연결된 터미널로 이동해서 트래픽 캡쳐
sudo tcpdump -i cilium_vxlan
CP 노드에 연결된 터미널로 이동해서 NGINX 서비스의 ClusterIP에 HTTP 요청
curl NGINX_SVC_CLUSTER_IP
OR
curl $(kubectl get svc nginx -o=jsonpath='{.spec.clusterIP}')
Worker 노드에 연결된 터미널로 이동해서 트래픽 캡쳐 결과 확인 하고
tcpdump
프로세스 종료CP 노드에 연결된 터미널로 돌아와서 노드의 IP 주소 확인
ip a
Cilium을 통해서 생성된 사용자 지정 객체 확인
kubectl get ciliumnodes
NGINX 서비스에 연결된 Endpoints 주소로 HTTP 요청
curl NGINX_ENDPOINT_IP
OR
curl $(kubectl get ep nginx -o=jsonpath='{.subsets[0].addresses[0].ip}:{.subsets[0].ports[0].port}')
NGINX Deployment의 Replica 갯수를 3개로 변경
kubectl scale deployment nginx --replicas=3
Pod가 추가로 생성됐는지 확인
kubectl get pod -l app=nginx -o wide
NGINX 서비스에 연결된 Endpoints 확인
kubectl get ep nginx
Last updated