I have 1 master and 2 nodes running and kube-proxy to debug.
kube-m1:/$ kubectl get pod -n kube-system kube-proxy-tmt58
NAME READY STATUS RESTARTS AGE
kube-proxy-tmt58 1/1 Running 6 439d
How can i specify a namespace to get kubectl logs
to debug a pod?
kube-m1:/$ kubectl logs kube-proxy-tmt58
Error from server (NotFound): pods "kube-proxy-tmt58" not found
I am new in kubernetes so, also would be great and very helpful to get some good and working guides or materials about pods and nodes debugging :)
Thanks a lot
CodePudding user response:
Just like you did it to get a pod, to specify a namespace you can pass -n
| --namespace
flag, so your command would look like
kubectl logs kube-proxy-tmt58 -n kube-system
CodePudding user response:
In addition to @jabbson answer I only want to mention and recommend you to save into the bookmarks kubectl Cheat Sheet. This page has huge amount of kubectl usage examples. It will help you a lot to deep into kubernetes world.
# Get commands with basic output
kubectl get services # List all services in the namespace
kubectl get pods --all-namespaces # List all pods in all namespaces
kubectl get pods -o wide # List all pods in the current namespace, with more details
kubectl get deployment my-dep # List a particular deployment
kubectl get pods # List all pods in the namespace
kubectl get pod my-pod -o yaml # Get a pod's YAML
# Describe commands with verbose output
kubectl describe nodes my-node
kubectl describe pods my-pod
# Get all worker nodes (use a selector to exclude results that have a label
# named 'node-role.kubernetes.io/master')
kubectl get node --selector='!node-role.kubernetes.io/master'
# Get all running pods in the namespace
kubectl get pods --field-selector=status.phase=Running
# Get ExternalIPs of all nodes
kubectl get nodes -o jsonpath='{.items[*].status.addresses[?(@.type=="ExternalIP")].address}'
# Logs
kubectl logs my-pod # dump pod logs (stdout)
kubectl logs -l name=myLabel # dump pod logs, with label name=myLabel (stdout)
kubectl logs my-pod --previous # dump pod logs (stdout) for a previous instantiation of a container
kubectl logs my-pod -c my-container # dump pod container logs (stdout, multi-container case)
kubectl logs -l name=myLabel -c my-container # dump pod logs, with label name=myLabel (stdout)
kubectl logs my-pod -c my-container --previous # dump pod container logs (stdout, multi-container case) for a previous instantiation of a container
kubectl logs -f my-pod # stream pod logs (stdout)
kubectl logs -f my-pod -c my-container # stream pod container logs (stdout, multi-container case)
kubectl logs -f -l name=myLabel --all-containers # stream all pods logs with label name=myLabel (stdout)