티스토리 뷰

Kubernetes

[Kubernetes] Pod 실습하기

SchoolDevops 2022. 4. 11. 11:35

POD 실습하기.

현재 기본 네임스페이스의 pod 목록 보기.

kubectl get pods

nginx pod 실행하기.

kubectl run nginx  --image=nginx nginx

pod/nginx created

현재 수행하는 pod 상세 정보 보기.

kubectl describe pod newpods-1234

Name:         newpods-1234
Namespace:    default
Priority:     0
Node:         node01/172.17.0.26
Start Time:   Wed, 10 Mar 2021 04:46:05 +0000
Labels:       tier=busybox
Annotations:  <none>
Status:       Running
IP:           10.244.1.3
IPs:
  IP:           10.244.1.3
Controlled By:  ReplicaSet/newpods
Containers:
  busybox:
    Container ID:  docker://247f2153a68cc2c859a9e4972b35234ee24120742ad44dbd8aa81d583116c143
    Image:         busybox
    Image ID:      docker-pullable://busybox@sha256:ce2360d5189a033012fbad1635e037be86f23b65cfd676b436d0931af390a2ac
    Port:          <none>
    Host Port:     <none>
    Command:
      sleep
      1000
    State:          Running
      Started:      Wed, 10 Mar 2021 04:46:07 +0000
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-qpwmc (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             True 
  ContainersReady   True 
  PodScheduled      True 
Volumes:
  default-token-qpwmc:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-qpwmc
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                 node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type    Reason     Age   From               Message
  ----    ------     ----  ----               -------
  Normal  Scheduled  105s  default-scheduler  Successfully assigned default/newpods-1234 to node01
  Normal  Pulling    104s  kubelet, node01    Pulling image "busybox"
  Normal  Pulled     103s  kubelet, node01    Successfully pulled image "busybox" in 998.529666ms
  Normal  Created    103s  kubelet, node01    Created container busybox
  Normal  Started    103s  kubelet, node01    Started container busybox

pod 목록 상세 보기.

kubectl get pods -o wide

NAME            READY   STATUS      RESTARTS   AGE     IP           NODE     NOMINATED NODE   READINESS GATES
newpods-1234   1/1     Running     0          2m51s   10.244.1.3   node01   <none>           <none>
newpods-3456   1/1     Running     0          2m51s   10.244.1.5   node01   <none>           <none>
newpods-dwqxv   1/1     Running     0          2m51s   10.244.1.4   node01   <none>           <none>
nginx           0/1     Completed   5          3m21s   10.244.1.2   node01   <none>           <none>

multiple containter in one pod

kubectl get pods -o wide
NAME            READY   STATUS             RESTARTS   AGE     IP           NODE     NOMINATED NODE   READINESS GATES
webapp          1/2     ImagePullBackOff   0          3m43s   10.244.1.6   node01   <none>           <none>
  • READY 필드를 살펴 보면 총 2개의 컨테이너중 1개가 수행되었음을 확인할 수 있음.
  • 실행되는 노드는 node01 임

pod 삭제.

kubectl delete pod webapp

pod "webapp" deleted

pod 생성하기.

kubectl run redis --image=redis-v1.1.1 --dry-run=client -o yaml
apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: redis
  name: redis
spec:
  containers:
  - image: redis-v1.1.1
    name: redis
    resources: {}
  dnsPolicy: ClusterFirst
  restartPolicy: Always
status: {}

vim redis-pods.yaml

kubectl create -f redis-pods.yaml 

pod/redis created

pod 수정해서 작업하기.

방법 1

vim redis-pods.yaml

... 내용을 수정하기. 

kubectl apply -f redis-pods.yaml

방법 2

kubectl edit pod redis

... 내용 수정 및 저장
... 자동으로 설정됨. 

pod/redis edited

결과보기

kubectl get pods
NAME            READY   STATUS             RESTARTS   AGE
redis           1/1     Running            0          5m8s
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함