Skip to content

kubectl exec for container access

kubectl exec is the command-line utility used to execute commands inside a running container within a Kubernetes cluster.^[400-devops-06-kubernetes-k8s-learning-04deployment-deployment.md]

Interactive Shell Access

To gain an interactive shell session within a specific container, the command requires specifying the target Pod and container name, along with pseudo-terminal (TTY) and standard input (stdin) allocation flags.^[400-devops-06-kubernetes-k8s-learning-04deployment-deployment.md]

The complete syntax includes flags for namespace, standard input, and TTY allocation, followed by the command to execute (e.g., /bin/bash):^[400-devops-06-kubernetes-k8s-learning-04deployment-deployment.md]

[kubectl](<./kubectl.md>) exec nginx-deployment-8475f9f6cc-7qhgb --container=my-nginx --namespace=default --stdin=true --tty=true -- /bin/bash

Sources

  • 400-devops-06-kubernetes-k8s-learning-04deployment-deployment.md