-
[Udemy] Interact with pods, logs, connect to pod and cleanupkubernetes/udemy 2025. 2. 12. 16:07
Pod 로그 확인
# 로그 확인
# Dump Pod logs kubectl logs <pod-name> kubectl logs my-first-pod --- 10.224.0.4 - - [12/Feb/2025:06:22:55 +0000] "GET / HTTP/1.1" 200 218 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36" "-" 2025/02/12 06:22:55 [error] 8#8: *163 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 10.224.0.4, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "20.249.195.85", referrer: "http://20.249.195.85/" 10.224.0.4 - - [12/Feb/2025:06:22:55 +0000] "GET /favicon.ico HTTP/1.1" 404 556 "http://20.249.195.85/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36" "-"
# 실시간 로그 확인
# Stream pod logs with -f option and access application to see logs kubectl logs <pod-name> kubectl logs -f my-first-pod
kubectl logs는 과거 로그를 조회할 때 사용하고, kubectl logs -f는 현재 진행 중인 로그를 실시간으로 확인할 때 사용
Pod 내 컨테이너에 연결
# Pod 내 컨테이너에 연결
# Connect to Nginx Container in a POD kubectl exec -it <pod-name> -- /bin/bash kubectl exec -it my-first-pod -- /bin/bash
# 컨테이너 내에서 index.html 파일 확인
root@my-first-pod:/# cd /usr/share/nginx/html root@my-first-pod:/usr/share/nginx/html# cat index.html <!DOCTYPE html> <html> <body style="background-color:lightgoldenrodyellow;"> <h1>Welcome to Stack Simplify</h1> <p>Kubernetes Fundamentals Demo</p> <p>Application Version: V1</p> </body>
이렇게 컨테이너 연결한 다음, 직접 컨테이너 내부에서 직접 파일을 확인해도 되고
하나의 명령어로도 가능하다.
kubectl exec -it <pod-name> -- env --- kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead. PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin HOSTNAME=my-first-pod NGINX_VERSION=1.17.10 NJS_VERSION=0.3.9 PKG_RELEASE=1~buster KUBERNETES_PORT_443_TCP_PORT=443 KUBERNETES_PORT_443_TCP_ADDR=10.0.0.1 KUBERNETES_SERVICE_HOST=10.0.0.1 KUBERNETES_SERVICE_PORT=443 KUBERNETES_SERVICE_PORT_HTTPS=443 KUBERNETES_PORT=tcp://10.0.0.1:443 KUBERNETES_PORT_443_TCP=tcp://10.0.0.1:443 KUBERNETES_PORT_443_TCP_PROTO=tcp TERM=xterm HOME=/root # Sample Commands kubectl exec -it my-first-pod -- env kubectl exec -it my-first-pod -- ls kubectl exec -it my-first-pod -- cat /usr/share/nginx/html/index.html
# 기존에 생성된 Pod 정보를 yaml 형태로 확인
# Get pod definition YAML output kubectl get pod my-first-pod -o yaml
# 기존에 생성된 Service 정보를 yaml 형태로 확인
kubectl get service my-first-service -o yaml
# 삭제
# Get all Objects in default namespace kubectl get all # Delete Services kubectl delete svc my-first-service # Delete Pod kubectl delete pod my-first-pod # Get all Objects in default namespace kubectl get all
[참고 영상]
Udemy - Azure Kubernetes Service with Azure DevOps and Terraform
섹션 4 : Kubernetes Fundamentals with kubectl - Imperative Approach
25. Step-08 : Interact with pods, logs, connect to pod and cleanup
[참고 문서]
'kubernetes > udemy' 카테고리의 다른 글
[Udemy] Services Demo with Cluster IP and Load Balancer Services (Imperative) (0) 2025.02.13 [Udemy] Deployments (0) 2025.02.13 [Udemy] ReplicaSet (0) 2025.02.12 [Udemy] Service (0) 2025.02.12 [Udemy] Pod 생성 및 삭제 (0) 2025.02.12