Exercise 8.1: Troubleshooting: Monitor Applications

  1. Pod 생성

    cat <<EOF | kubectl create -f -
    apiVersion: v1
    kind: Pod
    metadata:
      name: demo
    spec:
      containers:
      - name: busybox
        image: busybox
        command: [ "sleep" ]
        args: [ "10" ]
      - name: web
        image: nginx
        livenessProbe:
          httpGet:
            path: /
            port: 80
          initialDelaySeconds: 3
          periodSeconds: 3
    EOF
  2. Pod 상태 확인

    kubectl get pod demo
  3. Pod 상세 내용 확인

    kubectl describe pod demo
  4. 컨테이너 로그 확인

    {
        kubectl logs demo busybox
        kubectl logs demo web
    }
  5. Pod 상태 확인

    kubectl get pod demo
  6. Pod 삭제

    kubectl delete pod demo
  7. Pod 생성

    cat <<EOF | kubectl create -f -
    apiVersion: v1
    kind: Pod
    metadata:
      name: busybox
    spec:
      containers:
      - name: busybox
        image: busybox
        command: [ "sleep" ]
        args: [ "3600" ]
        securityContext:
          runAsUser: 2000
    EOF
  8. 생성한 Pod로 Shell 연결

    kubectl exec -it busybox -- /bin/sh
  9. DNS 서버 동작 확인

    nslookup www.linuxfoundation.org
  10. 로컬 DNS 설정 정보 확인

    cat /etc/resolv.conf
  11. 외부 연결 테스트

    nc www.linux.com 25
    wget http://www.linux.com
  12. Shell 프로세스 종료

    exit
  13. Pod 삭제

    kubectl delete pod busybox
  14. 데모 애플리케이션 배포

    cat <<EOF | kubectl apply -f -
    apiVersion: v1
    kind: Namespace
    metadata:
      name: demo
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: nginx
      labels:
        app: nginx
      namespace: demo
    spec:
      selector:
        matchLabels:
          app: nginx
      replicas: 3
      template:
        metadata:
          labels:
            app: nginx
        spec:
          containers:
          - image: nginx:1.20.1
            name: nginx
            ports:
            - containerPort: 80
              protocol: TCP
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: nginx
      namespace: demo
    spec:
      type: NodePort
      selector:
        app: nginx
      ports:
        - port: 80
    EOF
  15. 생성된 Service 및 Endpoint 확인

    kubectl get svc,ep -n demo
  16. kube-proxy가 실행중인지 확인

    ps -elf |grep kube-proxy
  17. kube-proxy 로그 확인

    sudo journalctl -a | grep proxy
    kubectl -n kube-system logs ds/kube-proxy
  18. iptable 규칙 확인

    sudo iptables-save |grep nginx
  19. 위에서 확인한 NodePort로 접근 확인

    curl localhost:NODE_PORT

Last updated