Exercise 2.3: Create a Basic Pod

  1. 쿠버네티스 API 리소스 목록 확인

    kubectl api-resources
  2. Pod 객체의 API 경로 확인

    kubectl get pod -v 6
  3. Ingress 객체의 API 경로 확인

    kubectl get ing -v 6
  4. Pod 객체의 필드 확인

    kubectl explain pod
  5. Pod 생성

    cat <<EOF | kubectl apply -f -
    apiVersion: v1
    kind: Pod
    metadata:
      name: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
    EOF
  6. Pod 상태 확인

    kubectl get pod nginx
  7. Pod 상세 내용 확인

    kubectl describe pod nginx
  8. Pod 삭제

    kubectl delete pod nginx
  9. Pod가 삭제 되었는지 확인

    kubectl get pod nginx
  10. PodSpec에 명시하는 컨테이너의 포트 정보가 무엇을 의미하는지 확인

    kubectl explain pod.spec.containers.ports
  11. NGINX 이미지 생성에 사용한 Dockerfile 확인 - https://hub.docker.com/_/nginx/tags

  12. Dockerfile에서 EXPOSE가 무엇을 의미하는지 확인 - https://docs.docker.com/engine/reference/builder/#expose

  13. Pod 생성

    cat <<EOF | kubectl apply -f -
    apiVersion: v1
    kind: Pod
    metadata:
      name: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80
    EOF
  14. NGINX 설정 파일 확인

    kubectl exec nginx -- cat /etc/nginx/conf.d/default.conf
  15. 생성된 Pod의 IP주소 확인

    kubectl get pod nginx -o wide
  16. CURL 명령어를 통해서 생성된 Pod의 IP주소로 HTTP 요청

    curl $(kubectl get pod nginx -o=jsonpath='{.status.podIP}')
  17. Pod 삭제

    kubectl delete pod nginx
  18. Service 생성

    cat <<EOF | kubectl apply -f -
    apiVersion: v1
    kind: Service
    metadata:
      name: nginx
      labels:
        app: nginx
    spec:
      selector:
        app: nginx
      ports:
      - protocol: TCP
        port: 80
    EOF
  19. 생성된 Service 확인

    kubectl get svc nginx -o wide
  20. 생성된 Endpoint 확인

    kubectl get ep nginx
  21. Pod 생성

    cat <<EOF | kubectl apply -f -
    apiVersion: v1
    kind: Pod
    metadata:
      name: nginx
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80
    EOF
  22. 생성된 Pod 확인

    kubectl get pod -o wide -l app=nginx
  23. Endpoint 확인

    kubectl get ep nginx
  24. CURL 명령어를 통해서 Service의 Cluster IP로 HTTP 요청

    curl $(kubectl get svc nginx -o=jsonpath='{.spec.clusterIP}')
  25. 위에서 생성한 Service를 NodePort 형식으로 변경

    cat <<EOF | kubectl apply -f -
    apiVersion: v1
    kind: Service
    metadata:
      name: nginx
    spec:
      selector:
        app: nginx
      type: NodePort
      ports:
      - protocol: TCP
        port: 80
    EOF
  26. Service의 IP주소 및 포트 확인

    kubectl get service nginx 
  27. 웹브라우저에서 ANY_NODE_IP:SERVICE_NODE_PORT 로 접속되는지 확인 - 아래 명령어로 주소 확인 가능

    echo "$(curl -s ifconfig.io):$(kubectl get svc nginx -o=jsonpath='{.spec.ports[0].nodePort}')"

Last updated