Kubernetes Commands for DevOps: A Guide with Examples

Photo by Ian Taylor on Unsplash

Kubernetes Commands for DevOps: A Guide with Examples

Table of contents

No heading

No headings in the article.

Kubernetes is an open-source container orchestration platform that helps DevOps teams to manage, deploy, and scale containerized applications. Kubernetes provides an extensive set of commands that enable DevOps engineers to interact with and manage their Kubernetes clusters. In this article, we will discuss some of the most commonly used Kubernetes commands with examples.

  • kubectl get

The kubectl get command is used to retrieve information about Kubernetes resources. You can use this command to list all the resources of a particular type. For instance, the following command lists all the pods running in a cluster:

rachana-uniyal@rachanauniyal:~$ kubectl get pods

This will return a list of all the pods running in the cluster along with their status and other details.

  • kubectl describe

The kubectl describe command provides detailed information about a specific resource in the cluster. For example, if you want to know more about a particular pod, you can use the following command:

rachana-uniyal@rachanauniyal:~$ kubectl describe pod <pod-name>

Replace <pod-name> with the actual name of the pod you want to describe. This command will give you detailed information about the pod, including its status, events, and container logs.

  • kubectl apply

The kubectl apply command is used to apply configuration files to a Kubernetes cluster. This command is useful when you want to create or update Kubernetes resources. For instance, you can use the following command to apply a YAML file that defines a deployment:

rachana-uniyal@rachanauniyal:~$ kubectl apply -f deployment.yaml

This will create a new deployment or update an existing one based on the contents of the deployment.yaml file.

  • kubectl logs

The kubectl logs command is used to view the logs of a container running in a pod. For example, if you want to view the logs of the container running in a pod named my-pod, you can use the following command:

rachana-uniyal@rachanauniyal:~$ kubectl logs my-pod

This will display the logs of the container running in the my-pod pod.

  • kubectl exec

The kubectl exec command is used to execute commands inside a container running in a pod. For instance, if you want to execute a command inside a container running in a pod named my-pod, you can use the following command:

rachana-uniyal@rachanauniyal:~$ kubectl exec my-pod -- <command>

Replace <command> with the actual command you want to execute inside the container. This command will run the specified command inside the container running in the my-pod pod.

These are some of the most commonly used Kubernetes commands that every DevOps engineer should be familiar with. By using these commands, DevOps teams can effectively manage, deploy, and scale their containerized applications on Kubernetes clusters.