This details various ways that you can interact with the code and data running inside your pod.
Access a Pod via Network
If you want access to a specific pod, even if it’s not serving traffic on the internet. To achieve this, Kubernetes has support built into it.
kubectl port-forward <pod-name> <localport>:<podport>
kubectl port-forward istio 5015:80
A secure tunnel is created from your local machine, though the K8s master, to the instance of the Pod running on one of the worker nodes.
Getting More Info with Logs
When you need to debug.
# downloads the current logs from the running instance
kubectl logs kuard
# continuously streams logs
kubectl logs -f kuard
# get logs from a previous instance of the container. Useful if your containers are continuously restarting at startup.
kubectl logs kuard --previous
-c
if you have multiple containers in your Pod, you can choose the one to view
Running Commands in your Container
If you need to execute commands in the context of the container itself.
# execute a command
kubectl exec <pod-name> <command>
# attach to bash
kubectl exec -it <pod-name> -- bash
# attach to running process
kubectl attach -it <pod-name>
This will provide you with an interactive shell inside the running container, so that you can perform more debugging. If you don’t have bash or some other terminal within your container, you can always attach to the running process. This is similar to to logs
allows you to send input to the process.
Copying Files to/from Pod
You can upload / download file from and to the containers.
# download file from remote to local
kubectl cp <pod-name>:/captures/capture3.txt ./capture3.txt
# upload file from local to remote
kubectl cp $HOME/config.txt <pod-name>:/config.txt
Generally speaking, copying files into a container is an anti-pattern. You really should treat the contents of a container as immutable.
See pod details (filtered)
see most important pod details
kubectl describe pod {name_of_your_pod_here}
get YAML
kubectl get pod {pod_name_goes_here} -o yaml
See resource consumption
If you’re interested in how your cluster is using resources, you can use top
to see the list of resources in use by either nodes or Pods.
kubectl top nodes
kubectl top pods --all-namespaces
By default it only displays Pods in the current namespace. You can use the flag to see resource usage by all Pods in the cluster.