Kubernetes_2

최시열·2023년 1월 30일
0
post-thumbnail

2023.01.30

5장 pod


kubectl create pod를 만드는 명령어

pod 1개당 하나의 ip 설정

get deployments 배포 상태를 확인


네임스페이스 실습

- namespace 실습

💨 blue 네임스페이스 생성
$ kubectl create namespace blue

💨 green 네임스페이스를 생성하는 yaml파일 만들기
kubectl create namespace green --dry-run -o yaml > ns-green.yaml

💨 yaml 파일 내용
apiVersion: v1
kind: Namespace
metadata:
  creationTimestamp: null
  name: green

💨 green 네임스페이스 생성
kubectl apply -f ns-green.yaml

💨 네임스페이스 조회
kubectl get namespaces

💨 green 네임스페이스 삭제
kublctl delete namespace green

++ 추가

💨 최근에 사용한 네임스페이스 조회
kubectl config current-context

💨 네임스페이스 생성
kubectl config set-context green@kubernetes --cluster=kubernetes --user=kubernetes-admin --namespace=green

💨 확인
kubectl config view

💨 네임스페이스 변경
kubectl config use-context green@kubernetes

💨 green에 있는 pod만 조회
kubectl get pod -n green

💨 모든 파드 조회
kubectl get pods --all-namespaces

💨 마지막에는 기본 네임스페이스로 돌려놓기
kubectl config use-context kubernetes-admin@kubernetes

pod 실습

💨 pod를 외부 트래픽으로 노출
kubectl expose deployment nginx-app --type=NodePort

💨 서비스 조회
kubectl get services
(이것두 된당..) kubectl get svc

💨 생성된 파드들의 안으로 들어가서 /usr/share/nginx/html에 있는 index.html을 ip주소로 바꾸어 로드밸런싱이 잘 되는지 확인해보자!!

kubectl exec -it nginx-app-8d447cf8b-v4lr5 /bin/bash
kubectl exec -it nginx-app-8d447cf8b-bc6mz /bin/bash
kubectl exec -it nginx-app-8d447cf8b-c2bvr /bin/bash

💨 VB에서 이런 식으로 포트 포워딩

💨 생성한 pod의 세부 내용 확인하기
kubectl describe deployments.apps nginx-app
kubectl describe service nginx-app

💨 ip로 접속하면 볼 수 있음

연습문제

1. 현재 namespace에서 동작중인 Pod는 몇 개인가 ?

kubectl get pods

2. 현재 시스템에서 동작중인 Pod 수는 ?

kubectl get pods --all-namespaces

3. 컨테이너 nginx를 실행하는 nginx-pod라는 이름의 Pod를 생성하시오.

kubectl run nginx-pod --image=nginx:1.14

4. 앞에서 생성 한 Pod의 image 정보를 확인하는 명령은 무엇인가?

kubectl describe pod nginx-pod

5. 앞에서 생성한 nginx-pod는 어느 node에 배치되었나?

kubectl get pod nginx-pod -o wide

6. 앞에서 생성한 Pod에는 몇 개의 컨테이너가 포함되어 있나 ?

kubectl get pods

7. 앞에서 생성한 Pod의 현재 상태는 어떠한가 ?

kubectl get pod nginx-pod

8. 새 Pod의 컨테이너 상태는 어떻습니까 ?

kubectl describe nginx-pod

9. “kubectl get pods” 명령의 출력에서 READY 열은 무엇을 의미하나?

들어가있는 컨테이너의 총 개수와 running이 되고 있는 컨테이너의 개수

10. 생성한 Pod를 삭제하시오.

kubectl delete pod nginx-pod

11. 컨테이너 image ‘redis123’을 실행하는 pod ‘redis’를 redis.yaml을 이용해 생성하시오.

kubectl run redis --image=redis123 --dry-run -o yaml > redis.yaml

kubectl apply -f redis.yaml 또는 kubectl create -f redis.yaml

kubectl get pods

12. 앞에서 만든 redis pod의 image를 redis로 수정하여 동작시키시오.

kubectl edit pod redis

profile
최시열

0개의 댓글