Kubernetes: Basic commands

Kubernetes

Once the installation of Kubernetes cluster is competed, let us go with the basic commands.

The below command lists the pods running on the cluster. Remember that there are several services used by Kubernetes already running as applications in pods.

[root@kubmaster01 ~]# kubectl get pods -A

==== ==
NAMESPACE     NAME      READY      STATUS      RESTARTS      AGE
kube-system calico-kube-controllers-5f9c988956-5v9fr 1/1 Running 3 (42m ago) 2d12h
kube-system calico-node-4vdc7 0/1 Running 2 (41m ago) 2d
kube-system calico-node-dwldq 0/1 Running 3 (42m ago) 2d12h
kube-system calico-node-pt5zx 0/1 Running 3 (42m ago) 2d12h
==== ===

In Kubernetes there is a concept of NameSpace which we will discuss later. The switch -A in the above command lists pods in all NameSpaces. The default NameSpace when no switch is used is the “default” NameSpace.

[root@kubmaster01 ~]# kubectl get pods -o wide -A

===== ===
NAMESPACE NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
kube-system calico-kube-controllers-5f9c988956-5v9fr 1/1 Running 3 (56m ago) 2d12h 172.16.152.76 kubmaster01 <none> <none>
kube-system calico-node-4vdc7 0/1 Running 2 (55m ago) 2d1h 192.168.146.131 localhost.localdomain <none> <none>
kube-system calico-node-dwldq 0/1 Running 3 (56m ago) 2d12h 192.168.146.130 kubworker01 <none> <none>
===== ===

The “-o wide” option in the above command provides additional details of the pods, compared to the previous command.

The below command provided information about the context presently used when accessing th

[root@kubmaster01 ~]# kubectl config current-context

======
kubernetes-admin@kubernetes
=======

The below command shows the different contexts that are presently available. On a newly installed cluster, only one will be available.

[root@kubmaster01 ~]# kubectl config get-contexts

=====
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
* kubernetes-admin@kubernetes kubernetes kubernetes-admin
==========

The below command lists the resources available in the system.

[root@kubmaster01 ~]# kubectl api-resources | head -n 5

===========
NAME    SHORTNAMES    APIVERSION    NAMESPACED    KIND
bindings v1 true Binding
componentstatuses cs v1 false ComponentStatus
configmaps cm v1 true ConfigMap
endpoints ep v1 true Endpoints
====== ===