10 Lesser-Known Kubernetes Commands Every DevOps Engineer Should Know

10 Lesser-Known Kubernetes Commands Every DevOps Engineer Should Know

Kubernetes is a popular container orchestration platform that offers several useful commands to deploy, manage, and maintain applications in containers. Some of these commands are well-known, but others are lesser-known yet equally important.

Here are ten lesser-known Kubernetes commands that every DevOps engineer should know:

1. kubectl taint

This command is used to taint a node, indicating that it requires specific conditions to run a pod.

Syntax:

kubectl taint nodes <node-name> key=value:taint-effect

Example:

kubectl taint nodes node1 app=nginx:NoSchedule

2. kubectl get events

The kubectl get events command displays the events of the cluster that occurred in the specified namespace.

Syntax:

kubectl get events -n <namespace>

Example:

kubectl get events -n my-namespace

3. kubectl rollout undo

This command is used to undo a previous rollout, whether it’s a deployment, daemonset, or statefulset.

Syntax:

kubectl rollout undo <resource_type> <resource_name>

Example:

kubectl rollout undo deployment my-deployment

4. kubectl explain

The kubectl explain command provides information on any Kubernetes API resource.

Syntax:

kubectl explain <resource_type>

Example:

kubectl explain pod

5. kubectl port-forward

The kubectl port-forward command is used to forward one or more local ports to a pod.

Syntax:

kubectl port-forward <pod-name> <local-port>:<pod-port>

Example:

kubectl port-forward my-pod 8080:80

6. kubectl top

This command provides system resource usage on a per-node or per-pod level.

Syntax:

kubectl top nodes
kubectl top pods

Example:

kubectl top nodes

7. kubectl attach

This command is used to attach to the running container of a pod.

Syntax:

kubectl attach <pod-name> -c <container-name>

Example:

kubectl attach my-pod -c nginx

8. kubectl patch

The kubectl patch command modifies one or more Kubernetes objects.

Syntax:

kubectl patch <resource-type> <resource-name> -p '{"<patch-operation>": {"key": "value"}}'

Example:

kubectl patch deployment my-deployment -p '{"spec": {"replica": 5}}'

9. kubectl get secrets

This command is used to retrieve all secrets of a specific namespace.

Syntax:

kubectl get secrets -n <namespace>

Example:

kubectl get secrets -n my-namespace

10. kubectl top pod

The kubectl top pod command provides CPU and memory usage of pods.

Syntax:

kubectl top pod <pod-name>

Example:

kubectl top pod my-pod

Conclusion

Kubernetes is a powerful platform that offers several commands to manage the deployment of applications in containers. The above ten lesser-known commands can help DevOps engineers manage and maintain Kubernetes resources more effectively.