Create Pod (Imperative)
Creates a new pod running Nginx using the imperative approach.
Explanation:
- kubectl run → Creates and runs a pod
- mynginx → Name for the pod
- --image=nginx → Specifies the container image to use
List Pods
Displays a list of all running pods in the current namespace.
Usage:
Use this command to check the status of your running pods, see their names, status, and age.
Detailed Pod Information
Shows additional information about pods including IP addresses and nodes.
Explanation:
- -o wide → Shows extended information
- Displays node name, IP addresses, and more
Describe Pod
Shows detailed information about a specific pod including events, conditions, and configuration.
Usage:
Use this command when troubleshooting pod issues to see events and detailed status information.
Delete Pod
Deletes a specific pod from the cluster.
Note:
If the pod is managed by a Deployment or ReplicaSet, it will be recreated automatically.
Create a pod running BusyBox with Shell
Creates a pod and attaches an interactive shell session to it.
Shell Commands to run:
List directory contents
Encode string to base64 (for Kubernetes Secrets)
Exit the shell session
Explanation:
- -it → Interactive terminal
- -- /bin/sh → Command to run inside the container
- Use exit to leave the shell
- The base64 command demonstrates encoding for Kubernetes Secrets
Force Delete Pod
Forcefully deletes a pod without waiting for graceful termination.
Warning:
This command immediately terminates the pod without allowing it to clean up. Use with caution.
Create from YAML (Declarative)
Creates Kubernetes resources defined in a YAML configuration file.
Get the YAML file
Download the myapp.yaml configuration file
Explanation:
- create -f → Create resources from file
- myapp.yaml → Configuration file defining the resources
- This is the declarative approach to Kubernetes management
Detailed Pod Information
Shows additional information about pods including IP addresses and nodes.
Explanation:
- -o wide → Shows extended information
- Displays node name, IP addresses, and more
Describe Pod
Shows detailed information about a specific pod including events, conditions, and configuration.
Usage:
Use this command when troubleshooting pod issues to see events and detailed status information.
Execute Command in Pod
Executes a command inside a running pod. This example opens a bash shell.
Shell Commands to run:
Print the value of the DBCON environment variable
Exit the shell session
Explanation:
- exec → Execute command in container
- -it → Interactive terminal
- myapp-pod → Name of the pod
- -- bash → Command to execute
Delete from YAML
Deletes all resources defined in a YAML configuration file.
Usage:
This is the cleanest way to remove resources that were created from a configuration file.