본문 바로가기

⭐ Kubernetes & EKS/EKS

EKS Pod 디스크립터 작성

728x90
반응형

# yaml 파일을 사용하여 작성

# pod 디스크립터 작성 (마스터 노스에서 실행)

# 디스크립터 작성

mkdir yaml

cd yaml

vim go-http-pod.yaml

# 파일내용

apiVersion: v1
kind: Pod
metadata:
  name: http-go
spec:
  containers:
  - name: http-go
    image: gasbugs/http-go
    ports:
    - containerPort: 8080

# 저장 후 실행

kubectl create -f go-http-pod.yaml

# pod의 정보를 보는 방법

kubectl get pod http-go

kubectl get pod http-go -o wide

kubectl get pod http-go -o yaml

kubectl describe pod http-go
ec2-user:~/environment $ kubectl get pod http-go -o yaml
apiVersion: v1
kind: Pod
metadata:
  annotations:
    kubernetes.io/psp: eks.privileged
  creationTimestamp: "2021-10-05T12:41:50Z"
  managedFields:
  - apiVersion: v1
    fieldsType: FieldsV1
    fieldsV1:
      f:spec:
        f:containers:
          k:{"name":"http-go"}:
            .: {}
            f:image: {}
            f:imagePullPolicy: {}
            f:name: {}
            f:ports:
              .: {}
              k:{"containerPort":8080,"protocol":"TCP"}:
                .: {}
                f:containerPort: {}
                f:protocol: {}
            f:resources: {}
            f:terminationMessagePath: {}
            f:terminationMessagePolicy: {}
        f:dnsPolicy: {}
        f:enableServiceLinks: {}
        f:restartPolicy: {}
        f:schedulerName: {}
        f:securityContext: {}
        f:terminationGracePeriodSeconds: {}
    manager: kubectl
    operation: Update
    time: "2021-10-05T12:41:50Z"
  - apiVersion: v1
    fieldsType: FieldsV1
    fieldsV1:
      f:status:
        f:conditions:
          k:{"type":"ContainersReady"}:
            .: {}
            f:lastProbeTime: {}
            f:lastTransitionTime: {}
            f:status: {}
            f:type: {}
          k:{"type":"Initialized"}:
            .: {}
            f:lastProbeTime: {}
            f:lastTransitionTime: {}
            f:status: {}
            f:type: {}
          k:{"type":"Ready"}:
            .: {}
            f:lastProbeTime: {}
            f:lastTransitionTime: {}
            f:status: {}
            f:type: {}
        f:containerStatuses: {}
        f:hostIP: {}
        f:phase: {}
        f:podIP: {}
        f:podIPs:
          .: {}
          k:{"ip":"192.168.6.116"}:
            .: {}
            f:ip: {}
        f:startTime: {}
    manager: kubelet
    operation: Update
    time: "2021-10-05T12:41:55Z"
  name: http-go
  namespace: default
  resourceVersion: "428945"
  selfLink: /api/v1/namespaces/default/pods/http-go
  uid: fa72343c-3469-40d4-899b-8926f3e83cd5
spec:
  containers:
  - image: gasbugs/http-go
    imagePullPolicy: Always
    name: http-go
    ports:
    - containerPort: 8080
      protocol: TCP
    resources: {}
    terminationMessagePath: /dev/termination-log
    terminationMessagePolicy: File
    volumeMounts:
    - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
      name: default-token-czdll
      readOnly: true
  dnsPolicy: ClusterFirst
  enableServiceLinks: true
  nodeName: ip-192-168-19-0.ap-northeast-2.compute.internal
  priority: 0
  restartPolicy: Always
  schedulerName: default-scheduler
  securityContext: {}
  serviceAccount: default
  serviceAccountName: default
  terminationGracePeriodSeconds: 30
  tolerations:
  - effect: NoExecute
    key: node.kubernetes.io/not-ready
    operator: Exists
    tolerationSeconds: 300
  - effect: NoExecute
    key: node.kubernetes.io/unreachable
    operator: Exists
    tolerationSeconds: 300
  volumes:
  - name: default-token-czdll
    secret:
      defaultMode: 420
      secretName: default-token-czdll
status:
  conditions:
  - lastProbeTime: null
    lastTransitionTime: "2021-10-05T12:41:50Z"
    status: "True"
    type: Initialized
  - lastProbeTime: null
    lastTransitionTime: "2021-10-05T12:41:55Z"
    status: "True"
    type: Ready
  - lastProbeTime: null
    lastTransitionTime: "2021-10-05T12:41:55Z"
    status: "True"
    type: ContainersReady
  - lastProbeTime: null
    lastTransitionTime: "2021-10-05T12:41:50Z"
    status: "True"
    type: PodScheduled
  containerStatuses:
  - containerID: docker://06d5f96fdcf87a6816992c29a71b700b0100dac71708087f5f916ab87a73af19
    image: gasbugs/http-go:latest
    imageID: docker-pullable://gasbugs/http-go@sha256:5cf243f818caf7a750761cfe2ff822a284d6eb459356318d3f0bd4b1efe141d9
    lastState: {}
    name: http-go
    ready: true
    restartCount: 0
    started: true
    state:
      running:
        startedAt: "2021-10-05T12:41:54Z"
  hostIP: 192.168.19.0
  phase: Running
  podIP: 192.168.6.116
  podIPs:
  - ip: 192.168.6.116
  qosClass: BestEffort
  startTime: "2021-10-05T12:41:50Z"

# 서비스 접근하기 (로컬환경 및 버추얼 박스에서만 가능할 듯... AWS 에서는 172.0.0.1 로 접근을 할 수 없으니...expose 애서 로드밸런싱으로 EXTERNAL-IP 받아서 확인해보는게 좋을듯)

kubectl port-forward http-go 8080:8080

127.0.0.1:8080

- 접근해서 서비스 확인하기

# 생성한 pod 삭제하기

kubectl delete -f go-http-pod.yaml

kubectl delete pod http-go
ec2-user:~/environment $ kubectl delete -f go-http-pod.yaml
pod "http-go-go" deleted
ec2-user:~/environment $

ec2-user:~/environment $ kubectl delete po http-go
pod "http-go" deleted
ec2-user:~/environment $

# 모든 pod 삭제

kubectl delete all --all

kubectl delete pod --all

# 만약 pod가 terminating 상태에서 삭제가 안될경우 아래의 명령어 사용

kubectl delete pods [pod name] --grace-period=0 --force
kubectl delete pods nginx-6799fc88d8-jb5xc --grace-period=0 --force

# pod에 log 보기

kubectl logs http-go

# pod에 주석달기

kubectl annotate pod http-go test1234=test1234

- kubectl get deploy 는 배포된 객체를 보여주고, kubectl get pod 는 현재 실행중인 pod 즉 서비스를 보여준다.

ec2-user:~/environment $ kubectl get deploy
NAME      READY   UP-TO-DATE   AVAILABLE   AGE
http-go   0/0     0            0           3h41m
jenkins   0/0     0            0           82m
ec2-user:~/environment $

- 그러므로 deploy에서는 조회되지만 pod가 보여지지 않는다면, 아마도 replicas 숫자가 0 이거나 pod가 정상적으로 실행되지 않았을 가능성이 크다.

끝.

728x90
반응형