SysAdmin 101
  • About Me
  • SSH
    • quick notes
    • socks tunneling
  • Tmux
    • quick notes
  • Kubernetes
    • quick notes
    • Setting up a K8S cluster
      • kubespray
      • metalLB
      • Nginx-Ingress
    • Storage
      • Persistent Storage
      • Persistent Storage Claim
  • Ansible
    • quick notes
    • ansible in a container
    • setup Ansible AWX
  • Docker
    • quick notes
    • docker compose
Powered by GitBook
On this page
  1. Kubernetes

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 on

  • Cluster management commands: Deal with nodes and the cluster at large: cluster-info, certificate, drain, and so on

  • Troubleshooting commands: describe, logs, attach, exec, and so on

  • Deployment commands: Deal with deployment and scaling: rollout, scale, auto-scale, and so on

  • Settings commands: Deal with labels and annotations: label, annotate, and so on

  • Misc 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
PreviousKubernetesNextSetting up a K8S cluster

Last updated 1 year ago