liveBook · Manning

Kubectl

As explained in Kubernetes for Developers

kubectl is the Kubernetes command-line client for creating, reading, updating, deleting, and otherwise managing Kubernetes resources.

kubectl is the command-line client for working with a Kubernetes cluster. Before deploying anything, connect and authenticate it to a cluster. That cluster can be hosted by a cloud provider or run locally. A simple check is `kubectl get pods`; an empty result can still mean the connection works. section 3.2.1

Use kubectl to create, read, update, and delete Kubernetes objects. The main commands are `create`, `get`, `apply`, and `delete`. A practical workflow is to describe a Deployment or Service in a YAML file, then submit that file rather than relying on one-off commands. The same configuration can be tried against a local cluster before being used elsewhere. section 3.2.5 section 3.4.3

Common tasks:

  • Create a Service from a file with `kubectl create -f service.yaml`, then inspect it with `kubectl get service`. Add `-w` to watch for changes, such as an external IP becoming available. section 3.2.5
  • After changing a Deployment’s container image in YAML, run `kubectl apply -f deploy.yaml`. Check `kubectl get deploy` to follow the update; Kubernetes replaces the old Pods rather than requiring you to replace them manually. section 3.2.7
  • Use `kubectl config get-contexts` and `kubectl config use-context $CONTEXT` to inspect and switch between previously connected clusters. section 3.4.1
  • Use `kubectl port-forward service/timeserver 8080:80` to reach a Service at `localhost:8080`, particularly when a local cluster has no external load balancer. section 3.4.3

Check an application update

Suppose a Deployment requests three Pods and its image changes from version 1 to version 2. After `kubectl apply -f deploy.yaml`, `kubectl get deploy` might show READY as `3/3` but UP-TO-DATE as `1`. The update is still underway; watch the Deployment or inspect its Pods until the current-version count catches up. section 3.2.7

How Kubernetes for Developers covers it

How deep it goes
Works through connection, resource commands, rollout checks, context switching, and port forwarding; defers detailed rollout strategies.
Examples
Shows Service creation and inspection, a Deployment image update, and port forwarding to a local Service.
What it assumes
Requires an authenticated connection to a Kubernetes cluster; introduces the commands through deployment tasks.
What you can do after
Operate/configure it to submit YAML, inspect resources and rollouts, switch clusters, and access a Service locally.
How it connects
Links Kubernetes API access with declarative configuration, Deployments, Pods, Services, and cluster contexts.

Also explained in

Compare how 11 books explain kubectl →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kubernetes for Developers. The section links point to the parts of the book it draws on.