kubectl get pods

생성된 pod 정보 확인

kubectl describe pods

자세한 pod 정보 확인. IP address, the ports used and a list of events related to the lifecycle of the Pod.

 

$ sleep 1; launch.sh
Starting Kubernetes. This is expected to take less than a minute.....
Kubernetes Started

$ kubectl get pods
NAME                                  READY   STATUS              RESTARTS   AGE
kubernetes-bootcamp-fb5c67579-xxdfc   0/1     ContainerCreating   0          4s
$ kubectl get pods
NAME                                  READY   STATUS    RESTARTS   AGE
kubernetes-bootcamp-fb5c67579-xxdfc   1/1     Running   0          52s
$ kubectl describe pods
Name:         kubernetes-bootcamp-fb5c67579-xxdfc
Namespace:    default
Priority:     0
Node:         minikube/10.0.0.17
Start Time:   Tue, 12 Apr 2022 07:15:00 +0000
Labels:       app=kubernetes-bootcamp
              pod-template-hash=fb5c67579
Annotations:  <none>
Status:       Running
IP:           172.18.0.3
IPs:
  IP:           172.18.0.3
Controlled By:  ReplicaSet/kubernetes-bootcamp-fb5c67579
Containers:
  kubernetes-bootcamp:
    Container ID:   docker://b525713ba1e40d0358493591c84aaa2444cc2bf13beb481a88aa27dc438e8d58
    Image:          gcr.io/google-samples/kubernetes-bootcamp:v1
    Image ID:       docker-pullable://jocatalin/kubernetes-bootcamp@sha256:0d6b8ee63bb57c5f5b6156f446b3bc3b3c143d233037f3a2f00e279c8fcc64af
    Port:           8080/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Tue, 12 Apr 2022 07:15:02 +0000
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-6vrph (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             True 
  ContainersReady   True 
  PodScheduled      True 
Volumes:
  default-token-6vrph:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-6vrph
    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  74s   default-scheduler  Successfully assigned default/kubernetes-bootcamp-fb5c67579-xxdfc to minikube
  Normal  Pulled     72s   kubelet            Container image "gcr.io/google-samples/kubernetes-bootcamp:v1" already present on machine
  Normal  Created    72s   kubelet            Created container kubernetes-bootcamp
  Normal  Started    72s   kubelet            Started container kubernetes-bootcamp



-. proxy를 통해 pod에 접근하여 pod 이름을 구하여 POD_NAME 환경변수로 export하기

 

먼저, 새로운 터미널에서 proxy start. 아웃풋을 확인하려면 다른 터미널에서 확인

 

$ echo -e "\n\n\n\e[92mStarting Proxy. After starting it will not output a response. e first Terminal Tab\n"; kubectl proxy

Starting Proxy. After starting it will not output a response. Please click the first Terminal Tab

Starting to serve on 127.0.0.1:8001

 

기존 터미널에서 kubectl 로 파드 이름을 구하여 환경변수로 지정하여 호출하기.

아웃풋 확인은 curl을 통해 호출한다.

 

$ export POD_NAME=$(kubectl get pods -o go-template --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}')
$ echo Name of the Pod: $POD_NAME
Name of the Pod: kubernetes-bootcamp-fb5c67579-xxdfc
$ curl http://localhost:8001/api/v1/namespaces/default/pods/$POD_NAME/proxy/
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-fb5c67579-xxdfc | v=1

 

해당 파드 내의 컨테이너에서 어플리케이션이 STDOUT으로 보내는 기록이 로그로 남고, 확인은 다음과 같이 한다.

 

$ kubectl logs $POD_NAME
Kubernetes Bootcamp App Started At: 2022-04-12T07:15:03.138Z | Running On:  kubernetes-bootcamp-fb5c67579-xxdfc 

Running On: kubernetes-bootcamp-fb5c67579-xxdfc | Total Requests: 1 | App Uptime: 1320.845 seconds | Log Time: 2022-04-12T07:37:03.983Z
Running On: kubernetes-bootcamp-fb5c67579-xxdfc | Total Requests: 2 | App Uptime: 1335.31 seconds | Log Time: 2022-04-12T07:37:18.448Z
Running On: kubernetes-bootcamp-fb5c67579-xxdfc | Total Requests: 3 | App Uptime: 1445.257 seconds | Log Time: 2022-04-12T07:39:08.395Z

 

pod가 up and running 상태이면 exec 명령어를 사용하여 

kubectl exec 의 옵션에 대한 정보:

$ kubectl exec --help
Execute a command in a container.

Examples:
  # Get output from running 'date' command from pod mypod, using the first
container by default
  kubectl exec mypod -- date
  
  # Get output from running 'date' command in ruby-container from pod mypod
  kubectl exec mypod -c ruby-container -- date
  
  # Switch to raw terminal mode, sends stdin to 'bash' in ruby-container from
pod mypod
  # and sends stdout/stderr from 'bash' back to the client
  kubectl exec mypod -c ruby-container -i -t -- bash -il
  
  # List contents of /usr from the first container of pod mypod and sort by
modification time.
  # If the command you want to execute in the pod has any flags in common (e.g.
-i),
  # you must use two dashes (--) to separate your command's flags/arguments.
  # Also note, do not surround your command and its flags/arguments with quotes
  # unless that is how you would execute it normally (i.e., do ls -t /usr, not
"ls -t /usr").
  kubectl exec mypod -i -t -- ls -t /usr
  
  # Get output from running 'date' command from the first pod of the deployment
mydeployment, using the first container by default
  kubectl exec deploy/mydeployment -- date
  
  # Get output from running 'date' command from the first pod of the service
myservice, using the first container by default
  kubectl exec svc/myservice -- date

Options:
  -c, --container='': Container name. If omitted, the first container in the pod
will be chosen
  -f, --filename=[]: to use to exec into the resource
      --pod-running-timeout=1m0s: The length of time (like 5s, 2m, or 3h, higher
than zero) to wait until at least one pod is running
  -i, --stdin=false: Pass stdin to the container
  -t, --tty=false: Stdin is a TTY

Usage:
  kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]
[options]

Use "kubectl options" for a list of global command-line options (applies to all
commands).

 

pod의 환경변수 확인: kubectl exec $POD_NAME -- env

 

pod의 컨테이너에서 bash 세션 생성 : kubectl exec -ti $POD_NAME -- bash

bash 세션으로 들어온 후, 컨테이너 안의 실제 어플리케이션 코드에 접근 가능.

어플리케이션이 정상 동작하는 상태인지 curl localhost로 확인.

 

root@kubernetes-bootcamp-fb5c67579-xxdfc:/# curl localhost:8080
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-fb5c67579-xxdfc | v=1

 

 

'aws > k8s, eks study' 카테고리의 다른 글

Difference between kubectl apply & create  (0) 2022.06.28
K8s command examples  (0) 2022.06.14
K8s 기본 네임스페이스 변경  (0) 2022.06.14
CKA 평가 항목  (0) 2022.04.21
brief concept of eks  (0) 2022.04.06

+ Recent posts