Belajar Sendiri

Kubernetes commands

One page per command. What it does, when to use it, how risky it is.

Look around

  • kubectl getLists objects as a table: pods, deployments, services and more.Risk: Safe
  • kubectl describeTells the whole story of one object, with its events at the end.Risk: Safe
  • kubectl explainShows the built-in docs for a field.Risk: Safe
  • kubectl waitWaits until something becomes true.Risk: Safe
  • kubectl versionShows the kubectl and cluster versions.Risk: Safe

Change the cluster

Rollouts

Debug

  • kubectl logsShows what a container printed.Risk: Safe
  • kubectl execRuns one command inside a running container.Risk: Careful
  • kubectl port-forwardOpens a private tunnel from your laptop to one pod.Risk: Safe
  • kubectl debugAdds a temporary debug container to a pod, with your own tools.Risk: Careful
  • kubectl topShows CPU and memory in use now (needs metrics-server).Risk: Safe
  • kubectl eventsShows the manager's notice board: scheduled, pulled, started, and warnings.Risk: Safe

Where am I?

Nodes

  • kubectl cordonStops new pods going to a node. Pods already there stay.Risk: Careful
  • kubectl drainCordons a node and evicts its pods. emptyDir data is lost.Risk: Can lose work
  • kubectl taint nodesPuts a lock on a node. Only pods with the key (a toleration) may come.Risk: Careful

Packages and overlays

  • kubectl kustomizeBuilds YAML from a base plus an overlay (names, labels, images, replicas).Risk: Safe
  • helm templateFills a chart with values and prints the YAML. Installs nothing.Risk: Safe
  • helmInstalls a chart as a release, and later upgrades or rolls it back.Risk: Careful

Run the cluster itself (CKA)

  • sshOpens a shell inside one node: the stall's back room. exit takes you back.Risk: Safe
  • systemctlTalks to systemd, the machine's power room: is a service like the kubelet running? Start, restart or stop it.Risk: Careful
  • journalctlReads a service's diary: the log lines systemd keeps for it.Risk: Safe
  • crictl podsLooks straight at the stove: the pods, containers and images containerd has on this one node.Risk: Safe
  • kubeadm initTurns a fresh machine into the manager's office: certificates, kubeconfig files, static pod manifests and a join token.Risk: Careful
  • kubeadm joinBrings a new machine into the cluster as a stall, with a ticket and the office's ID check.Risk: Careful
  • sudo kubeadm upgrade planUpgrades a kubeadm cluster's control plane. plan only looks; apply changes the first control-plane node; node does the others.Risk: Careful
  • kubeadm certs check-expirationShows when the control plane's certificates expire, and renews them. The CAs are not renewed.Risk: Careful
  • etcdctlSaves a snapshot of the running etcd: a photocopy of the order book. Without the certificate flags it waits forever.Risk: Safe
  • etcdutlReads a snapshot file: its hash, revision, keys and size. In etcd 3.7, etcdctl no longer does this.Risk: Safe
  • etcdutlUnpacks a snapshot into a new data folder. Point etcd at it, and the cluster goes back in time. Newer objects are lost.Risk: Can lose work
  • kubectl certificate approveApproves a CertificateSigningRequest, so the cluster signs that ID card. It names who, not what they may do.Risk: Careful