Kubernetes Components
Pod : The smallest deployable unit in Kubernetes, representing a
group of one or more containers that share network and storage
resources. Pods are the atomic unit of scheduling and run on a single
node.
Node : A worker machine in the Kubernetes cluster that hosts pods.
Nodes are the fundamental computing hardware units that provide
computational resources for running containerized applications.
Objects : Persistent entities in the Kubernetes system that represent
the state of the cluster, including deployments, services, pods, and
other resources that define the desired cluster configuration.
Monitoring : Tracks resource utilization and performance of nodes,
pods, and containers using commands like kubectl top to provide
insights into cluster health and resource consumption.
Deployment : A Kubernetes object that manages the lifecycle of
pods, ensuring a specified number of replica pods are running and
facilitating updates and rollbacks of application versions.
Service : An abstraction that defines a logical set of pods and a
policy to access them, providing network connectivity and load
balancing for applications across the cluster.
Kubernetes Components
Ingress : A Kubernetes object that manages external access to
services, typically HTTP/HTTPS, providing routing, SSL termination, and
name-based virtual hosting capabilities.
Endpoints : Represents the network addresses of pods backing a
service, dynamically updated to track which pods are available to
handle requests.
DaemonSet : Ensures a specific pod runs on all (or selected) nodes in
the cluster, typically used for cluster-wide services like monitoring,
logging, or node-level system daemons.
Jobs : Kubernetes objects that create one or more pods to perform a
specific task and ensure the task completes successfully, useful for
batch processing and one-time computational tasks.
Rollout : Manages the deployment and update process, allowing
controlled updates, rollbacks, and tracking of deployment revisions.
Secret : Kubernetes objects used to store and manage sensitive
information like passwords, OAuth tokens, and SSH keys, providing a
secure way to handle confidential data in the cluster.
Pod
PodCommands
Commands
Basic Pod Commands
Basic Podget
kubectl Commands
pod: List all pods in current namespace
kubectl get pod:
kubectl get pod -oList all Detailed
wide: pods in current namespace
pod information with node details
kubectl get pod -w: Watch live pod status updates with node details
kubectl get pod -o wide: Detailed pod information
kubectl
kubectl get
get pod
pod -o-w: Watch
yaml: livepod
Export podconfiguration
status updates
in YAML format
kubectl get pod -o yaml: Export pod configuration
kubectl describe pod <pod_name>: Detailed pod status in YAML
andformat
events
kubectl describe pod <pod_name>: Detailed
kubectl delete pod <pod_name>: Remove specific pod pod status and events
kubectl delete pod <pod_name>: Remove specific pod
Advanced Pod Commands
Advanced Podpod
kubectl edit Commands
<pod_name>: Modify pod configuration live
kubectl edit pod <pod_name>:
kubectl logs <pod_name>: Modify
View pod logspod configuration live
kubectl
kubectl logs-it<pod_name>:
exec <pod_name>View pod logs
/bin/bash: Interactive shell inside pod
kubectl exec -it <pod_name> /bin/bash: Interactive shell inside pod
Additional Useful Commands
Additional Useful
kubectl get podsCommands
--show-labels: List pods with their labels
kubectl get pods --show-labels: List pods with their labels
kubectl get pods --field-selector=status.phase=Running: Filter running pods
kubectl get pods --field-selector=status.phase=Running:
kubectl top pod: Resource usage metrics Filter running pods
kubectl
kubectl top pod: Resource
port-forward usage metrics
<pod_name> <local_port>:<pod_port>: Network port
kubectl
forwardingport-forward <pod_name> <local_port>:<pod_port>: Network port
forwarding
Node Commands
Node Management Commands
kubectl describe node <node_name>: Detailed node information and status
kubectl get node <node_name>: Get basic node details
kubectl get node <node_name> -o yaml: Export node configuration in YAML
format
kubectl drain node <node_name>: Prepare node for maintenance by
evicting all pods
kubectl cordon node <node_name>: Mark node as unschedulable for new
pods
kubectl uncordon node <node_name>: Mark node as schedulable again
Additional Useful Commands
kubectl get nodes: List all cluster nodes
kubectl top node: View node resource usage
kubectl label node <node_name>: Add or modify node labels
Object Creation Commands
Resource Creation
kubectl apply -f <file_name>.yaml: Create resource from YAML file
kubectl apply -f <file1>.yaml -f <file2>.yaml: Create from multiple files
kubectl apply -f ./<directory_name>: Create all files in directory
kubectl apply -f https://<url>: Create from URL
Pod Creation
kubectl run <pod_name> --image=<image_name>: Create basic pod
kubectl run <pod_name> --image=<image_name> --port <port> --
expose: Create pod and expose as service
kubectl run <pod_name> --image=<image_name> --dry-run=client -
o yaml > <file_name>.yaml: Generate Pod YAML file
Deployment Creation
kubectl create deployment <name> --image=<image_name>: Create
deployment
kubectl create deployment <name> --image=<image_name> --dry-
run=client -o yaml > <file_name>.yaml: Generate Deployment YAML file
ConfigMap Creation
kubectl create configmap <name> --from-literal=<key>=<value>:
Create from key-value pairs
kubectl create configmap <name> --from-file=<file_name>: Create
from file
kubectl create configmap <name> --from-env-file=<file_name>:
Create from environment file
Secret Creation
kubectl create secret generic <name> --from-literal=<key>=<value>:
Create from key-value pairs
kubectl create secret generic <name> --from-file=<file_name>: Create
from file
Monitoring Usage Commands
Node Resource Monitoring
kubectl top node: Display resource usage for all nodes
kubectl top node <node_name>: Get specific node's CPU and
memory utilization
Pod Resource Monitoring
kubectl top pod: Display resource usage for all pods
kubectl top pod <pod_name>: Get specific pod's CPU and memory
utilization
Additional Monitoring Commands
kubectl top pod -n <namespace>: View pod resources in specific
namespace
kubectl top pod --sort-by=cpu: Sort pods by CPU usage
kubectl top pod --sort-by=memory: Sort pods by memory usage
Deployment Commands
Basic Deployment Commands
kubectl get deployment: List all deployments
kubectl get deployment <deployment_name>: Get specific deployment
kubectl get deployment <deployment_name> -o yaml: Get deployment
in YAML format
kubectl get deployment <deployment_name> -o wide: Detailed
deployment information
Deployment Management
kubectl edit deployment <deployment_name>: Modify deployment
configuration
kubectl describe deployment <deployment_name>: Detailed
deployment status
kubectl delete deployment <deployment_name>: Remove deployment
kubectl scale deployment <deployment_name> --replicas=<number>:
Change deployment replica count
Service Commands
Service Management Commands
kubectl get service: List all services in current namespace
kubectl get service <service_name>: Get specific service details
kubectl get service <service_name> -o yaml: Get service in YAML
format
kubectl get service <service_name> -o wide: Detailed service
information
kubectl edit service <service_name>: Modify service configuration
kubectl describe service <service_name>: Detailed service status
kubectl delete service <service_name>: Remove service from
cluster
Ingress Commands
Ingress Management Commands
kubectl get ingress: List all ingresses in current namespace
kubectl get ingress -o yaml: Get ingress in YAML format
kubectl get ingress -o wide: Detailed ingress information
kubectl edit ingress <ingress_name>: Modify ingress configuration
kubectl describe ingress <ingress_name>: Detailed ingress status
kubectl delete ingress <ingress_name>: Remove ingress from
cluster
Endpoints Commands
Endpoints Management Commands
kubectl get endpoints: List all endpoints in current namespace
kubectl get endpoints <endpoints_name>: Get specific endpoint
details
kubectl get endpoints -A: List endpoints across all namespaces
DaemonSet Commands
DaemonSet Management Commands
kubectl get daemonset: List all daemonsets in current namespace
kubectl get daemonset <daemonset_name>: Get specific
daemonset details
kubectl get daemonset <daemonset_name> -o yaml: Get
daemonset in YAML format
kubectl edit daemonset <daemonset_name>: Modify daemonset
configuration
kubectl describe daemonset <daemonset_name>: Detailed
daemonset status
kubectl delete daemonset <daemonset_name>: Remove
daemonset from cluster
Job Commands
Job Management Commands
kubectl get job: List all jobs in current namespace
kubectl get job <job_name>: Get specific job details
kubectl get job <job_name> -o yaml: Get job in YAML format
kubectl edit job <job_name>: Modify job configuration
kubectl describe job <job_name>: Detailed job status
kubectl delete job <job_name>: Remove job from cluster
Rollout Commands
Deployment Rollout Management
kubectl rollout restart deployment <deployment_name>: Restart
deployment
kubectl rollout undo deployment <deployment_name>: Undo to
previous deployment revision
kubectl rollout undo deployment <deployment_name> --to-
revision=<revision_number>: Undo to specific deployment revision
kubectl rollout history deployment <deployment_name>: View all
deployment revisions
kubectl rollout history deployment <deployment_name> --
revision=<revision_number>: Get details of specific revision
Secret Commands
Secret Management Commands
kubectl get secret: List all secrets in current namespace
kubectl get secret <secret_name>: Get specific secret details
kubectl get secret <secret_name> -o yaml: Get secret in YAML
format
kubectl describe secret <secret_name>: Detailed secret
information
kubectl delete secret <secret_name>: Remove secret from cluster
kubectl edit secret <secret_name>: Modify secret configuration