Access your pods

This details various ways that you can interact with the code and data running inside your pod.

Using Port Forwarding

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 kuard 8080:8080

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

Running Commands in your Container

If you need to execute commands in the context of the container itself.

# execute a command
kubectl exec kuard date

# interactive session
kubectl exec -it kuard ash

Copying Files to and from Containers

You can upload / download file from and to the containers.

# download file from container
kubectl cp <pod-name>:/captures/capture3.txt ./capture3.txt

# upload file from local
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.