Kubernetes 101 : Kubectl basic commands

Kubectl command:

Kubectl is the command we use to create, modify delete or check the logs of the kubernetes components (nodes, pods, sevices, replicasets, deployments,...).

Checking the nodes in a cluster:

To check the nodes in a cluster we use the below command:

Deploying pods:

We normally don't deploy pods directly, we go through the deployment "layer":


We can check the deployment status using:

We get the below result which contains the deployment name and the number of replicas:

To check out the newly deployed pods, we use:

The pod's mame is combination of the deployment_name and a random hash number.
The deployment component takes care of creating the pods.


Replicasets are used to keep a number of pod replicas to guarantee availability of the applications.
To get the status of replicas, we use:

We can see there are five debian replicas.

Changing the configuration of components:

We get an auto-generated file to which we can make the needed changes.
The old version of the pod terminates and a new one with the new configuration gets deployed.
We can use the "kubectl get pods"to check that.

Checking the logs:

We can check the logs using for debugging purposes:

We can have more information by checking the state of the pod using:

Getting a shell-like access inside the application:

We could use it with nginx or MySQL images for example to get a prompt into the shell of the image.

Deleting a kubernetes component:

To delete a component, for example a pod, we delete the deployment that we used to create it:

We check to see if the pod has been deleted using the "kubectl get pods" command.


We create, modify or delete resources at the deployment level, kubernetes takes care of the rest.

Creating components using a Yaml configuration file:

When the amount of options is too overwhelming to fit on the kubectl command line, we can use a Yaml configuration file to create the components. We them run the file using:

Example :

Below the Yaml file for the creation of five replicas of a Debian pod:

We check the creation of the pods using the "kubectl get pods" command.
To delete resources we use:


Leave as a comment: