Introduction: The book “Kubernetes in Action” by Marko Luksa is a valuable resource for learning Kubernetes. However, as Kubernetes evolves, some commands in the book have become deprecated. This post provides updated commands to ensure compatibility with the latest Kubernetes version.
Original and Updated Commands:
- kubectl get rc
- Original Command:
kubectl get rc - Updated Command:
kubectl get replicasetorkubectl get rs - Explanation: ReplicationControllers (rc) are deprecated in favor of ReplicaSets (rs).
- Original Command:
- kubectl scale rc
- Original Command:
kubectl scale rc <name> --replicas=<number> - Updated Command:
kubectl scale replicaset <name> --replicas=<number>or typically done via deployments (kubectl scale deployment <name> --replicas=<number>).
- Original Command:
- kubectl delete rc
- Original Command:
kubectl delete rc <name> - Updated Command:
kubectl delete replicaset <name>or better yet, manage via deployments:- Explanation: Instead of deleting individual ReplicaSets, it’s more efficient to manage the entire lifecycle of your applications using deployments. For example:
- Benefit: This ensures that all associated resources (like ReplicaSets and Pods) are managed consistently and according to the desired state defined in the deployment.
- Original Command:
- kubectl rolling-update
- Original Command:
kubectl rolling-update <old-controller> <new-controller> --image=<image> - Updated Command: Deprecated. Use deployments with:
- Explanation: Rolling updates are now handled by deployments, which provide a more robust and declarative way to manage updates. For example:or
- Benefit: Deployments automatically manage the rollout process, ensuring zero downtime and rollback capabilities if something goes wrong.
- Original Command:
- kubectl run
- Original Command:
kubectl run <pod-name> --image=<image> - Updated Command: Now typically creates a pod directly; use deployments for managed pods:
- Original Command:
Commands Still Valid:
- kubectl create namespace
- Original Command:
kubectl create ns <name> - Updated Command: Still valid. The recommended explicit command:
- Original Command:
- kubectl exec
- Original Command:
kubectl exec <pod-name> -- <command> - Updated Command: Still valid and widely used. No changes required.
- Original Command:
- kubectl proxy
- Original Command:
kubectl proxy - Updated Command: Still valid and widely used. No changes required.
- Original Command:
- kubectl expose
- Original Command:
kubectl expose rc <name> --port=<port> - Updated Command:
kubectl expose replicaset <name> --port=<port>or more commonly, expose deployments or services:
- Original Command:
- kubectl autoscale
- Original Command:
kubectl autoscale rc <name> - Updated Command:
kubectl autoscale deployment <deployment-name> --min=<min-replicas> --max=<max-replicas> --cpu-percent=<target-cpu-percent>
- Original Command:
- kubectl create
- Original Command:
kubectl create -f <file.yaml> - Updated Command: Often replaced with
kubectl applyto maintain idempotency:
- Original Command:
Additional Valid Commands:
- kubectl annotate: Adds or updates annotations on a resource.
- kubectl cluster-info: Displays information about the Kubernetes cluster.
- kubectl logs: Retrieves logs from a container in a pod.
- kubectl port-forward: Forwards one or more local ports to a pod.
- kubectl describe: Shows detailed information about a resource.
- kubectl patch: Updates a resource using a patch.
- kubectl replace: Replaces a resource by applying a new configuration (generally replaced by
kubectl applyfor idempotency). - kubectl edit: Edits a resource on the server directly.
- kubectl rollout status: Shows the status of a rollout for a deployment.
- kubectl set image: Updates the image of a container in a deployment.
- kubectl create configmap: Creates a ConfigMap from a file, directory, or literal value.
- kubectl create secret: Creates a secret from a file, directory, or literal value.
- kubectl cp: Copies files and directories to and from containers.
Notes and Recommendations:
- ReplicationControllers (rc) have been fully replaced by ReplicaSets (rs), which are now managed through Deployments.
- Imperative management commands (
kubectl create) are gradually replaced with declarative (kubectl apply), ensuring better state management. - Rolling updates and resource management are now managed declaratively via Deployments and StatefulSets, rather than imperative
kubectl rolling-update. - It’s recommended to always use deployments and statefulsets to manage pod lifecycles, scaling, and updates, as this aligns better with Kubernetes’ declarative philosophy and current best practices.

