Commands

Basics

  1. Create a new deployment: kubectl create deployment [DEPLOYMENT_NAME] --image=[IMAGE_NAME]

  2. Scale a deployment: kubectl scale deployment [DEPLOYMENT_NAME] --replicas=[REPLICA_COUNT]

  3. Expose a deployment as a service: kubectl expose deployment [DEPLOYMENT_NAME] --port=[PORT_NUMBER] --target-port=[TARGET_PORT_NUMBER] --type=[SERVICE_TYPE]

  4. Delete a deployment: kubectl delete deployment [DEPLOYMENT_NAME]

  5. Delete a service: kubectl delete service [SERVICE_NAME]

  6. Get information about a deployment: kubectl get deployment [DEPLOYMENT_NAME]

  7. Get information about a service: kubectl get service [SERVICE_NAME]

Pods

  1. Create a new pod: kubectl run [POD_NAME] --image=[IMAGE_NAME]

  2. Delete a pod: kubectl delete pod [POD_NAME]

  3. Get information about a pod: kubectl get pod [POD_NAME]

  4. View logs from a pod: kubectl logs [POD_NAME]

  5. Execute a command inside a pod: kubectl exec [POD_NAME] -- [COMMAND]

ConfigMaps and Secrets

  1. Create a new ConfigMap: kubectl create configmap [CONFIGMAP_NAME] --from-literal=[KEY]=[VALUE]

  2. Create a new Secret: kubectl create secret generic [SECRET_NAME] --from-literal=[KEY]=[VALUE]

  3. Get information about a ConfigMap: kubectl get configmap [CONFIGMAP_NAME]

  4. Get information about a Secret: kubectl get secret [SECRET_NAME]

Namespaces

  1. Create a new namespace: kubectl create namespace [NAMESPACE_NAME]

  2. Switch to a different namespace: kubectl config set-context --current --namespace=[NAMESPACE_NAME]

  3. Get information about all namespaces: kubectl get namespaces

Advanced

  1. Apply a configuration file: kubectl apply -f [FILE_PATH]

  2. Get detailed information about a deployment: kubectl describe deployment [DEPLOYMENT_NAME]

  3. Get detailed information about a pod: kubectl describe pod [POD_NAME]

  4. Get detailed information about a service: kubectl describe service [SERVICE_NAME]

  5. Port-forward to a pod: kubectl port-forward [POD_NAME] [LOCAL_PORT]:[REMOTE_PORT]

Last updated