In this lesson, we will explore the purpose and usage of theDocumentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
kubectl exec command, which functions very similarly to docker exec. This powerful command enables you to execute commands inside a running container, making it an invaluable tool for container management and troubleshooting.
Basic Syntax
The basic syntax for thekubectl exec command is as follows:
-c flag. For a pod with a single container, you only need to append -- followed by the command you wish to execute.
Listing Container Filesystem Contents
For instance, if you want to view the contents of a container’s filesystem, you can run:Getting an Interactive Shell
Sometimes it is more convenient to enter into an interactive shell session within the container. For this purpose, add the-i (interactive) and -t (tty) flags. For example:
Use Cases and Best Practices
This approach is especially useful when you need to inspect file permissions, install debugging utilities, or run diagnostic tools such astcpdump to gain insights into the container’s behavior. However, it is important to note that:
Avoid using
kubectl exec in production environments as it may interfere with the running workload. Instead, limit its use to development or staging environments and consider using more robust troubleshooting methods for production setups.