Commands
Basics
Create a new deployment:
kubectl create deployment [DEPLOYMENT_NAME] --image=[IMAGE_NAME]
Scale a deployment:
kubectl scale deployment [DEPLOYMENT_NAME] --replicas=[REPLICA_COUNT]
Expose a deployment as a service:
kubectl expose deployment [DEPLOYMENT_NAME] --port=[PORT_NUMBER] --target-port=[TARGET_PORT_NUMBER] --type=[SERVICE_TYPE]
Delete a deployment:
kubectl delete deployment [DEPLOYMENT_NAME]
Delete a service:
kubectl delete service [SERVICE_NAME]
Get information about a deployment:
kubectl get deployment [DEPLOYMENT_NAME]
Get information about a service:
kubectl get service [SERVICE_NAME]
Pods
Create a new pod:
kubectl run [POD_NAME] --image=[IMAGE_NAME]
Delete a pod:
kubectl delete pod [POD_NAME]
Get information about a pod:
kubectl get pod [POD_NAME]
View logs from a pod:
kubectl logs [POD_NAME]
Execute a command inside a pod:
kubectl exec [POD_NAME] -- [COMMAND]
ConfigMaps and Secrets
Create a new ConfigMap:
kubectl create configmap [CONFIGMAP_NAME] --from-literal=[KEY]=[VALUE]
Create a new Secret:
kubectl create secret generic [SECRET_NAME] --from-literal=[KEY]=[VALUE]
Get information about a ConfigMap:
kubectl get configmap [CONFIGMAP_NAME]
Get information about a Secret:
kubectl get secret [SECRET_NAME]
Namespaces
Create a new namespace:
kubectl create namespace [NAMESPACE_NAME]
Switch to a different namespace:
kubectl config set-context --current --namespace=[NAMESPACE_NAME]
Get information about all namespaces:
kubectl get namespaces
Advanced
Apply a configuration file:
kubectl apply -f [FILE_PATH]
Get detailed information about a deployment:
kubectl describe deployment [DEPLOYMENT_NAME]
Get detailed information about a pod:
kubectl describe pod [POD_NAME]
Get detailed information about a service:
kubectl describe service [SERVICE_NAME]
Port-forward to a pod:
kubectl port-forward [POD_NAME] [LOCAL_PORT]:[REMOTE_PORT]
Last updated