Basic Kubernetes commands to start with

Kubernetes is an open-source platform that automates the deployment, scaling, and management of containerized applications. It allows you to orchestrate and manage multiple containers in a distributed environment. In this blog, we will discuss some basic commands for Kubernetes.

1. kubectl run

Thekubectl run command is used to create a new deployment or job in Kubernetes. A deployment is a higher-level abstraction that manages a set of replicas of your application. A job is a lower-level abstraction that manages a set of pods that perform a single task.

The basic syntax for the kubectl run command is as follows:kubectl run [OPTIONS] NAME –image=IMAGE [COMMAND] [ARG…]

Here, OPTIONS are any additional options that you want to pass to Kubernetes while creating the deployment or job, NAME is the name of the deployment or job that you want to create, IMAGE is the name of the container image that you want to run, and COMMAND and ARG are optional commands and arguments to pass to the container.

Here’s an example kubectl run command:kubectl run my-deployment –image=my-image:latest

This command creates a new deployment with the name my-deployment and runs the container image my-image:latest.

2. kubectl get

The kubectl get command is used to retrieve information about resources in Kubernetes. It allows you to view the status of deployments, pods, services, and other Kubernetes resources.

The basic syntax for the kubectl get command is as follows:kubectl get [OPTIONS] [RESOURCE] [NAME]

Here, OPTIONS are any additional options that you want to pass to Kubernetes while retrieving the information, RESOURCE is the name of the Kubernetes resource that you want to retrieve information about, and NAME is the name of the specific resource that you want to retrieve information about.

Here’s an example kubectl get command:kubectl get pods

This command retrieves information about all the pods in the default namespace.

3. kubectl describe

The kubectl describe command is used to retrieve detailed information about a Kubernetes resource. It allows you to view the status, configuration, and events related to a particular resource.

The basic syntax for the kubectl describe command is as follows:kubectl describe [OPTIONS] [RESOURCE] [NAME]

Here, OPTIONS are any additional options that you want to pass to Kubernetes while retrieving the information, RESOURCE is the name of the Kubernetes resource that you want to retrieve information about, and NAME is the name of the specific resource that you want to retrieve information about.

Here’s an examplekubectl describe command:kubectl describe pod my-pod

This command retrieves detailed information about the pod with the name my-pod.

4. kubectl apply

The kubectl apply command is used to apply a configuration file to Kubernetes. This configuration file defines the desired state of your Kubernetes resources.

The basic syntax for the kubectl apply command is as follows:kubectl apply [OPTIONS] -f FILENAME

Here, OPTIONS are any additional options that you want to pass to Kubernetes while applying the configuration file, and FILENAME is the name of the configuration file.

Here’s an example kubectl apply command:kubectl apply -f my-deployment.yaml

This command applies the configuration file my-deployment.yaml to Kubernetes.

5. kubectl delete

The kubectl delete command is used to delete a Kubernetes resource. It allows you to remove deployments, pods, services, and other Kubernetes resources from your cluster

Leave a comment