# Cluster info
kubectl cluster-info
kubectl version
kubectl config view
# Get resources
kubectl get nodes
kubectl get pods
kubectl get services
kubectl get all
# Describe resources
kubectl describe node NODE_NAME
kubectl describe pod POD_NAME
# Logs and events
kubectl logs POD_NAME
kubectl logs POD_NAME -c CONTAINER_NAME
kubectl get events
# Create pod
kubectl run nginx --image=nginx
# Delete pod
kubectl delete pod nginx
# YAML generation
kubectl run nginx --image=nginx --dry-run=client -o yaml > pod.yaml
kubectl create -f pod.yaml
# Exec into pod
kubectl exec -it POD_NAME -- /bin/sh
# Port-forward
kubectl port-forward POD_NAME 8080:80
# Create deployment
kubectl create deployment my-deploy --image=nginx
# Update deployment
kubectl set image deployment/my-deploy nginx=nginx:1.19
# Scale deployment
kubectl scale deployment my-deploy --replicas=3
# Rollout
kubectl rollout status deployment/my-deploy
kubectl rollout undo deployment/my-deploy
# Expose pod/deployment
kubectl expose pod nginx --port=80 --target-port=80 --type=NodePort
kubectl expose deployment my-deploy --port=80 --type=ClusterIP
# View services
kubectl get svc
# Describe service
kubectl describe svc my-deploy
# List namespaces
kubectl get ns
# Create namespace
kubectl create ns my-namespace
# Use namespace
kubectl config set-context --current --namespace=my-namespace
# Create ConfigMap
kubectl create configmap my-config --from-literal=key1=value1
kubectl create configmap app-config --from-file=config.txt
# View and describe
kubectl get configmaps
kubectl describe configmap my-config
# Create secret
kubectl create secret generic my-secret --from-literal=password=12345
# View and describe
kubectl get secrets
kubectl describe secret my-secret
# Example YAML with volume
apiVersion: v1
kind: Pod
metadata:
name: volume-pod
spec:
containers:
- name: busybox
image: busybox
command: ["sleep", "3600"]
volumeMounts:
- mountPath: "/data"
name: my-volume
volumes:
- name: my-volume
emptyDir: {}
# Imperative command
kubectl create deployment nginx --image=nginx
kubectl expose deployment nginx --port=80 --type=NodePort
# YAML creation
kubectl run nginx --image=nginx --dry-run=client -o yaml > pod.yaml
kubectl create -f pod.yaml
# Labels and selectors
kubectl label pod nginx app=web
kubectl get pods --selector app=web
# Node selector in pod spec
spec:
nodeSelector:
disktype: ssd
β This complete Kubernetes reference includes essential commands and patterns used in KodeKloud labs. Practice them to become confident in real-world K8s operations!