quick notes
Using kubectl: First thing is getting bash completion
source <$(kubectl completion bash)
and make it permanent
kubectl completion bash > .bash_kubectl
echo "source ~/.bash_kubectl" >> ~/.bashrc"
Using kubectl effectively
kubectl is your Swiss Army knife. It can do pretty much anything around a cluster. Under the hood, kubectl connects to your cluster via the API. It reads your ~/.kube/config file (by default, this can be overridden with the KUBECONFIG environment variable or the --kubeconfig command-line argument), which contains the information necessary to connect to your cluster or clusters. The commands are divided into multiple categories:
Generic commands: Deal with resources in a generic way:
create, get, delete, run, apply, patch, replace
, and so onCluster management commands: Deal with nodes and the cluster at large:
cluster-info, certificate, drain
, and so onTroubleshooting commands:
describe, logs, attach, exec
, and so onDeployment commands: Deal with deployment and scaling:
rollout, scale, auto-scale
, and so onSettings commands: Deal with labels and annotations:
label, annotate
, and so onMisc commands:
help, config, version
Customization commands: Integrate the kustomize.io capabilities into kubectl
Configuration commands: Deal with contexts, switch between clusters and namespaces, set current context and namespace, and so on
Common commands
kubectl get -A all (-A for all namespaces)
kubectl get namespaces
kubectl get ns (shorthand for above)
kubectl get -n (namespace) pods/services/deployments/replicaset/all
kubectl get -n (namespace) po/svc/deploy/rs (shorthand for above)
kubectl apply -f (yamlfile.yaml)
kubectl delete -f (yamlfile.yaml)
kubectl delete -n (namespace) pods (podname)
kubectl explain (resource)
kubectl describe (resource)
kubectl edit (resource)
kubectl logs (podname)
kubectl api-versions
kubectl api-resources
kubectl get ingress -n (namespace)
kubectl get secrets -n (namespace)
kubectl get configmaps -n (namespace)
kubectl cluster-info
kubectl config view
kubectl config get-users
kubectl config delete-users
Last updated