Must-know Kubernetes commands for power users.

 

Cluster Management

  • kubectl cluster-info # Displays information about the cluster
  • kubectl get nodes # Lists nodes in the cluster
  • kubectl describe node [node-name] # Shows details of a node
  • kubectl drain [node-name] # Drains a node of pods before maintenance
  • kubectl cordon [node-name] # Marks a node as unschedulable
  • kubectl uncordon [node-name] # Marks a node as schedulable
  • kubectl top nodes # Shows resource usage statistics for nodes

Pod Management

  • kubectl get pods # Lists all pods in the current namespace
  • kubectl get pods --all-namespaces # Lists all pods across all namespaces
  • kubectl describe pod [pod-name] # Shows details of a pod
  • kubectl logs [pod-name] # Displays the logs of a pod
  • kubectl exec -it [pod-name] -- /bin/sh # Runs a command inside a pod
  • kubectl delete pod [pod-name] # Deletes a pod
  • kubectl run [pod-name] --image=[image] # Creates a pod with a specific image
  • kubectl port-forward [pod-name] [local-port]:[pod-port] # Forwards ports from the pod to your machine
  • kubectl top pod [pod-name] # Displays resource usage of a pod

Deployments Management

  • kubectl get deployments # Lists all deployments
  • kubectl describe deployment [deployment-name] # Shows details of a deployment
  • kubectl apply -f [deployment-file.yaml] # Applies changes from a YAML deployment file
  • kubectl delete deployment [deployment-name] # Deletes a deployment
  • kubectl rollout status deployment [deployment-name] # Checks the status of a deployment
  • kubectl rollout undo deployment [deployment-name] # Reverts the last deployment update
  • kubectl scale deployment [deployment-name] --replicas=[number] # Scales a deployment
  • kubectl set image deployment/[deployment-name] [container]=[new-image] # Updates the image of a container in a deployment

Services Management

  • kubectl get services # Lists all services
  • kubectl describe service [service-name] # Shows details of a service
  • kubectl expose deployment [deployment-name] --type=[type] --port=[port] # Exposes a deployment as a service
  • kubectl delete service [service-name] # Deletes a service
  • kubectl port-forward service/[service-name] [local-port]:[service-port] # Forwards ports from the service

Namespace Management

  • kubectl get namespaces # Lists all namespaces
  • kubectl create namespace [namespace-name] # Creates a new namespace
  • kubectl delete namespace [namespace-name] # Deletes a namespace
  • kubectl config set-context --current --namespace=[namespace-name] # Sets the current namespace

ConfigMaps and Secrets Management

  • kubectl get configmaps # Lists all ConfigMaps
  • kubectl describe configmap [configmap-name] # Shows details of a ConfigMap
  • kubectl create configmap [configmap-name] --from-file=[file] # Creates a ConfigMap from a file
  • kubectl delete configmap [configmap-name] # Deletes a ConfigMap
  • kubectl get secrets # Lists all secrets
  • kubectl describe secret [secret-name] # Shows details of a secret
  • kubectl create secret generic [secret-name] --from-literal=[key]=[value] # Creates a secret from literal values
  • kubectl delete secret [secret-name] # Deletes a secret

Volumes and Storage Management

  • kubectl get pv # Lists all persistent volumes (PVs)
  • kubectl describe pv [pv-name] # Shows details of a PV
  • kubectl get pvc # Lists all persistent volume claims (PVCs)
  • kubectl describe pvc [pvc-name] # Shows details of a PVC
  • kubectl delete pvc [pvc-name] # Deletes a PVC

Roles and Access Management (RBAC)

  • kubectl get roles # Lists all roles
  • kubectl get rolebindings # Lists all role bindings
  • kubectl describe role [role-name] # Shows details of a role
  • kubectl create role [role-name] --verb=[action] --resource=[resource] # Creates a role
  • kubectl delete role [role-name] # Deletes a role
  • kubectl get clusterroles # Lists all cluster-level roles
  • kubectl describe clusterrole [clusterrole-name] # Shows details of a cluster role
  • kubectl create clusterrole [clusterrole-name] --verb=[action] --resource=[resource] # Creates a cluster role
  • kubectl delete clusterrole [clusterrole-name] # Deletes a cluster role

Jobs and CronJobs Management

  • kubectl get jobs # Lists all jobs
  • kubectl describe job [job-name] # Shows details of a job
  • kubectl create job [job-name] --image=[image] # Creates a job
  • kubectl delete job [job-name] # Deletes a job
  • kubectl get cronjobs # Lists all cronjobs
  • kubectl describe cronjob [cronjob-name] # Shows details of a cronjob
  • kubectl create cronjob [cronjob-name] --schedule="*/5 * * * *" --image=[image] # Creates a cronjob with a schedule
  • kubectl delete cronjob [cronjob-name] # Deletes a cronjob

Verification and Debugging

  • kubectl get events # Lists all events in the cluster
  • kubectl describe [resource] [resource-name] # Shows details of any resource
  • kubectl get all # Lists all resources in the current namespace
  • kubectl explain [resource] # Displays the documentation of a resource
  • kubectl diff -f [file.yaml] # Compares a YAML file with the current state
  • kubectl api-resources # Lists all available API resources
  • kubectl api-versions # Lists all API versions
  • kubectl version # Displays the version of kubectl and the server

Other Useful Commands

  • kubectl edit [resource] [resource-name] # Edits a resource live
  • kubectl patch [resource] [resource-name] --patch '{...}' # Applies a patch to a resource
  • kubectl label [resource] [resource-name] [label]=[value] # Adds a label to a resource
  • kubectl annotate [resource] [resource-name] [annotation]=[value] # Adds an annotation to a resource
  • kubectl rollout restart deployment [deployment-name] # Restarts a deployment
  • kubectl taint nodes [node-name] [key]=[value]:[effect] # Adds a taint to a node
  • kubectl wait --for=condition=[condition] pod/[pod-name] # Waits for a resource to reach a condition

Comments

Popular posts from this blog

Unveiling the "TOP" command: Analyze your system like a power user.

Must-know Docker commands for power users.

How to Install Stable Diffusion on Windows