Updating Deprecated Commands in “Kubernetes in Action”

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:

  1. kubectl get rc
    • Original Commandkubectl get rc
    • Updated Commandkubectl get replicaset or kubectl get rs
    • Explanation: ReplicationControllers (rc) are deprecated in favor of ReplicaSets (rs).
  2. kubectl scale rc
    • Original Commandkubectl scale rc <name> --replicas=<number>
    • Updated Commandkubectl scale replicaset <name> --replicas=<number> or typically done via deployments (kubectl scale deployment <name> --replicas=<number>).
  3. kubectl delete rc
    • Original Commandkubectl delete rc <name>
    • Updated Commandkubectl 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.
  4. kubectl rolling-update
    • Original Commandkubectl 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.
  5. kubectl run
    • Original Commandkubectl run <pod-name> --image=<image>
    • Updated Command: Now typically creates a pod directly; use deployments for managed pods:

Commands Still Valid:

  1. kubectl create namespace
    • Original Commandkubectl create ns <name>
    • Updated Command: Still valid. The recommended explicit command:
  2. kubectl exec
    • Original Commandkubectl exec <pod-name> -- <command>
    • Updated Command: Still valid and widely used. No changes required.
  3. kubectl proxy
    • Original Commandkubectl proxy
    • Updated Command: Still valid and widely used. No changes required.
  4. kubectl expose
    • Original Commandkubectl expose rc <name> --port=<port>
    • Updated Commandkubectl expose replicaset <name> --port=<port> or more commonly, expose deployments or services:
  5. kubectl autoscale
    • Original Commandkubectl autoscale rc <name>
    • Updated Commandkubectl autoscale deployment <deployment-name> --min=<min-replicas> --max=<max-replicas> --cpu-percent=<target-cpu-percent>
  6. kubectl create
    • Original Commandkubectl create -f <file.yaml>
    • Updated Command: Often replaced with kubectl apply to maintain idempotency:

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 apply for 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.