본문 바로가기

Kubernetes

쿠버네티스 기초 Pods

쿠버네티스에서는 도커처럼 container 하나만 바로 실행이 불가하다. 쿠버네티스 안에 container는 Pod 안에서 동작한다.

pod은 각자의 IP를 가질수 있고 서비스에 꼭 필요 있는 container들을 하나의 pod에서 동시에 실행시킬수도 있다. pod안의 container들은 동일 네트워크, NameSpace에서 실행 되기 떄문에 호스트 이름, 네트워크 인터페이스를 공유한다.

developui-MacBook-Pro:~ develop$ kubectl get service --all-namespaces 
NAMESPACE              NAME                        TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                  AGE
default                hello-minikube              NodePort    10.96.37.58      <none>        8080:31701/TCP           2d
default                kubernetes                  ClusterIP   10.96.0.1        <none>        443/TCP                  2d4h
kube-system            kube-dns                    ClusterIP   10.96.0.10       <none>        53/UDP,53/TCP,9153/TCP   2d4h
kubernetes-dashboard   dashboard-metrics-scraper   ClusterIP   10.101.130.194   <none>        8000/TCP                 3m1s
kubernetes-dashboard   kubernetes-dashboard        ClusterIP   10.98.82.177     <none>        80/TCP                   3m1s

새로운 process를 추가 해보겠습니다.

developui-MacBook-Pro:~ develop$ kubectl run nginx --image=nginx
kubectl run --generator=deployment/apps.v1 is DEPRECATED and will be removed in a future version. Use kubectl run --generator=run-pod/v1 or kubectl create instead.
deployment.apps/nginx created

pods을 자세하게 보기위해서 Kubectl describe pods 실행

developui-MacBook-Pro:~ develop$ kubectl get pods
NAME                              READY   STATUS    RESTARTS   AGE
hello-minikube-797f975945-jhq9s   1/1     Running   3          2d1h
nginx-6db489d4b7-xnpks            1/1     Running   0          19s
developui-MacBook-Pro:~ develop$ kubectl describe pods
Name:         hello-minikube-797f975945-jhq9s
Namespace:    default
Priority:     0
Node:         m01/192.168.99.101
Start Time:   Tue, 17 Mar 2020 15:10:14 +0900
Labels:       app=hello-minikube
              pod-template-hash=797f975945
Annotations:  <none>
Status:       Running
IP:           172.17.0.2
IPs:
  IP:           172.17.0.2
Controlled By:  ReplicaSet/hello-minikube-797f975945
Containers:
  echoserver:
    Container ID:   docker://903ea8fb360a6be7d628a9c828984a796cf85dc819744205a0575f08a7809517
    Image:          k8s.gcr.io/echoserver:1.10
    Image ID:       docker-pullable://k8s.gcr.io/echoserver@sha256:cb5c1bddd1b5665e1867a7fa1b5fa843a47ee433bbb75d4293888b71def53229
    Port:           <none>
    Host Port:      <none>
    State:          Running
      Started:      Thu, 19 Mar 2020 15:27:28 +0900
    Last State:     Terminated
      Reason:       Error
      Exit Code:    255
      Started:      Wed, 18 Mar 2020 22:15:59 +0900
      Finished:     Thu, 19 Mar 2020 15:27:08 +0900
    Ready:          True
    Restart Count:  3
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-85v4v (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             True 
  ContainersReady   True 
  PodScheduled      True 
Volumes:
  default-token-85v4v:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-85v4v
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:          <none>


Name:         nginx-6db489d4b7-xnpks
Namespace:    default
Priority:     0
Node:         m01/192.168.99.101
Start Time:   Thu, 19 Mar 2020 16:34:04 +0900
Labels:       pod-template-hash=6db489d4b7
              run=nginx
Annotations:  <none>
Status:       Running
IP:           172.17.0.7
IPs:
  IP:           172.17.0.7
Controlled By:  ReplicaSet/nginx-6db489d4b7
Containers:
  nginx:
    Container ID:   docker://52086d14341ebad07f4c620a2ad5bd52067eca3ddcf6170f4660be01e17d02c1
    Image:          nginx
    Image ID:       docker-pullable://nginx@sha256:2539d4344dd18e1df02be842ffc435f8e1f699cfc55516e2cf2cb16b7a9aea0b
    Port:           <none>
    Host Port:      <none>
    State:          Running
      Started:      Thu, 19 Mar 2020 16:34:20 +0900
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-85v4v (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             True 
  ContainersReady   True 
  PodScheduled      True 
Volumes:
  default-token-85v4v:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-85v4v
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type    Reason     Age        From               Message
  ----    ------     ----       ----               -------
  Normal  Scheduled  <unknown>  default-scheduler  Successfully assigned default/nginx-6db489d4b7-xnpks to m01
  Normal  Pulling    78s        kubelet, m01       Pulling image "nginx"
  Normal  Pulled     63s        kubelet, m01       Successfully pulled image "nginx"
  Normal  Created    63s        kubelet, m01       Created container nginx
  Normal  Started    63s        kubelet, m01       Started container nginx

지금 현재 모든 서비스의 namespace를 확인해보겠습니다.

developui-MacBook-Pro:~ develop$ kubectl get service --all-namespaces 
NAMESPACE              NAME                        TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                  AGE
default                hello-minikube              NodePort    10.96.37.58      <none>        8080:31701/TCP           2d1h
default                kubernetes                  ClusterIP   10.96.0.1        <none>        443/TCP                  2d5h
kube-system            kube-dns                    ClusterIP   10.96.0.10       <none>        53/UDP,53/TCP,9153/TCP   2d5h
kubernetes-dashboard   dashboard-metrics-scraper   ClusterIP   10.101.130.194   <none>        8000/TCP                 60m
kubernetes-dashboard   kubernetes-dashboard        ClusterIP   10.98.82.177     <none>        80/TCP                   60m

pod의 모든 ps 정보를 확인 하기

developui-MacBook-Pro:~ develop$ kubectl get pods -o wide
NAME                              READY   STATUS    RESTARTS   AGE    IP           NODE   NOMINATED NODE   READINESS GATES
hello-minikube-797f975945-jhq9s   1/1     Running   3          2d1h   172.17.0.2   m01    <none>           <none>
nginx-6db489d4b7-xnpks            1/1     Running   0          4m     172.17.0.7   m01    <none>           <none>

'Kubernetes' 카테고리의 다른 글

쿠버네티스 기초 Replication Controller  (0) 2020.03.26
쿠버네티스 기초 YAML 파일 작성 하기  (0) 2020.03.22
kubectl autocomplete 설정하기  (0) 2020.03.18
Minikube tutorial  (0) 2020.03.17
Kubectl 설치(mac os)  (0) 2020.03.17