~/.kube/config
is the local configuration file (contains all the contexts, information about the clusters and user credentials)
# get current context
kubectl config current-context
# display context configuration
kubectl config get-contexts
# change context
kubectl config use-context <cluster-name>
# display version
kubectl version
# display cluster information
kubectl cluster-info
# display cluster configuration
kubectl config get-clusters
# get health information for the control plane components (the scheduler, the controller manager and etcd)
kubectl get componentstatuses
# list all the nodes in the cluster and report their status and Kubernetes version
kubectl get nodes
# show the CPU and memory capacity of each node, and how much of each is currently in use
kubectl top pods
# view sereval resources at once
kubectl get deploy,rs,po,svc,ep
# create resources from a manifest file
kubectl create -f <filename>
# create or update resources from a manifest file
kubectl update -f <filename>
# delete resources from a manifest file
kubectl delete -f <filename>
# list all namespaces
kubectl get namespaces
# create a new namespace
kubectl create ns hello-there
# list pods of a specific namespace
kubectl get pods --namespace kube-system
# list pods of all namespaces
kubectl get pods -A
# get more information about a pod
kubectl describe pod
# get log information of a specific pod
kubectl logs
# get pod yaml definition
kubectl get pod -o yaml
# watch pods
watch kubectl get pod --all-namespaces
# desribe a pod
kubectl describe pod <pod-name> --namespace <namespace>
# get pod logs
kubectl logs [--tail=20] [--since=1h] <pod-name>
# display metrics about a pod and its containers
kubectl top pod <pod-name> --containers
# execute commands inside a pod (for investigation purpose)
kubectl exec -it <pod-name> -n <namespace> -- /bin/bash
# download or upload files from a container
kubectl cp my-file.txt <namespace>/<pod-name>:my-file.txt
kubectl cp <namespace>/<pod-name>:my-file.txt my-file.txt
# see all service accounts in all namespaces
kubectl get ServiceAccount -A
# see all secrets in all namespaces
kubectl get secrets -A
# create a CronJob
kubectl create cronjob my-cron --image=busybox --schedule="*/5 * * * *" -- echo hello
# update a CronJob
kubectl edit cronjob/my-cron
# update a CronJob with a specific IDE
KUBE_EDITOR="nano" kubectl edit cronjob/my-cron
# delete a CronJob
kubectl delete cronjob my-cron
kubectl get deployment
# see all services in all namespaces
kubectl get services -A
kubectl get events --sort-by=.metadata.creationTimestamp
# see all ingresses in all namespaces
kubectl get ingress -A
# see a resource definition
kubectl get ingress mymicroservice -o yaml
kubectl scale
kubectl port-forward xxx 8080:80
# runs a proxy to the Kubernetes API Server
kubectl proxy
# review agent pool specification
az aks show --resource-group myrgname --name myaksname --query agentPoolProfiles
# scale agent pool (2 nodes here)
az aks scale --resource-group myrgname --name myaksname --node-count 2 --query properties.provisioningState
gcloud container clusters create mycluster
gcloud container clusters list
kubectl get nodes
gcloud container clusters delete linuxfoundation
# find and delete pods
kubectl delete pods $(kubectl get pods -o=name | grep mypodname | sed "s/^.\{4\}//")
Issue | Advice |
---|---|
Pod with status CreateContainerConfigError |
Look at the pod logs (kubectl logs podxxx ), the issue should be detailed there |