{"id":1624,"date":"2024-08-14T07:04:02","date_gmt":"2024-08-14T07:04:02","guid":{"rendered":"http:\/\/shijuvarghese.com\/?p=1624"},"modified":"2026-04-29T10:38:43","modified_gmt":"2026-04-29T10:38:43","slug":"kubernetes-basic-commands","status":"publish","type":"post","link":"http:\/\/shijuvarghese.com\/?p=1624","title":{"rendered":"Kubernetes: Basic commands"},"content":{"rendered":"<p>Once the installation of Kubernetes cluster is competed, let us go with the basic commands.<\/p>\n<p>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.<\/p>\n<p>Below command is used to view the CLuster&#8217;s configuration.<\/p>\n<p><strong>[root@CFX-91-KUBEMASTER ~]#<\/strong> kubectl config view<\/p>\n<p>==== ==== ==<br \/>\n<em>apiVersion: v1<\/em><br \/>\n<em>clusters:<\/em><br \/>\n<em>&#8211; cluster:<\/em><br \/>\n<em>certificate-authority-data: DATA+OMITTED<\/em><br \/>\n<em>server: https:\/\/192.168.0.91:6443<\/em><br \/>\n<em>name: kubernetes<\/em><\/p>\n<p><em>contexts:<\/em><br \/>\n<em>&#8211; context:<\/em><br \/>\n<em>cluster: kubernetes<\/em><br \/>\n<em>user: kubernetes-admin<\/em><br \/>\n<em>name: <strong>kubernetes-admin@kubernetes<\/strong><\/em><br \/>\n<em>current-context: kubernetes-admin@kubernetes<\/em><br \/>\n<em>kind: Config<\/em><br \/>\n<em>preferences: {}<\/em><\/p>\n<p><em>users:<\/em><br \/>\n<em>&#8211; name: kubernetes-admin<\/em><br \/>\n<em>user:<\/em><br \/>\n<em>client-certificate-data: DATA+OMITTED<\/em><br \/>\n<em>client-key-data: DATA+OMITTED<\/em><br \/>\n<em>[root@CFX-91-KUBEMASTER ~]<\/em><\/p>\n<p>===== ==== ===<\/p>\n<p>You may be running multiple clusters in your organization, and therefore you will have to switch between managing these clusters. That is, you will have to switch between the context name, where each will be unique for each cluster.<\/p>\n<p>Below command finds the context you are managing.<\/p>\n<p><strong>[root@CFX-91-KUBEMASTER ~]#<\/strong> kubectl config current-context<\/p>\n<p>==== === ==<br \/>\nkubernetes-admin@kubernetes<\/p>\n<p>===== ===<\/p>\n<p><strong>[root@CFX-91-KUBEMASTER ~]#<\/strong> kubectl config use-context NewContextName<\/p>\n<p>The below command lists all the available commands under\u00a0<em>config<\/em>.<\/p>\n<p><strong>[root@CFX-91-KUBEMASTER ~]#<\/strong> kubectl config &#8211;help<\/p>\n<p>==== ===<\/p>\n<p>Available Commands:<br \/>\ncurrent-context Display the current-context<br \/>\ndelete-cluster Delete the specified cluster from the kubeconfig<br \/>\ndelete-context Delete the specified context from the kubeconfig<br \/>\ndelete-user Delete the specified user from the kubeconfig<br \/>\nget-clust &#8230;&#8230;..<\/p>\n<p>==== ===<\/p>\n<p><strong>[root@kubmaster01 ~]#<\/strong> kubectl get pods -A<\/p>\n<p><em>==== ==<\/em><br \/>\n<em> NAMESPACE\u00a0 \u00a0 \u00a0NAME\u00a0 \u00a0 \u00a0 READY\u00a0 \u00a0 \u00a0 STATUS\u00a0 \u00a0 \u00a0 RESTARTS\u00a0 \u00a0 \u00a0 AGE<\/em><br \/>\n<em> kube-system calico-kube-controllers-5f9c988956-5v9fr 1\/1 Running 3 (42m ago) 2d12h<\/em><br \/>\n<em> kube-system calico-node-4vdc7 0\/1 Running 2 (41m ago) 2d<\/em><br \/>\n<em> kube-system calico-node-dwldq 0\/1 Running 3 (42m ago) 2d12h<\/em><br \/>\n<em> kube-system calico-node-pt5zx 0\/1 Running 3 (42m ago) 2d12h<\/em><br \/>\n<em>==== ===<\/em><\/p>\n<p>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 &#8220;default&#8221; NameSpace.<\/p>\n<p><strong>[root@kubmaster01 ~]#<\/strong> kubectl get pods -o wide -A<\/p>\n<p><em>===== ===<\/em><br \/>\n<em>NAMESPACE NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES<\/em><br \/>\n<em>kube-system calico-kube-controllers-5f9c988956-5v9fr 1\/1 Running 3 (56m ago) 2d12h 172.16.152.76 kubmaster01 &lt;none&gt; &lt;none&gt;<\/em><br \/>\n<em>kube-system calico-node-4vdc7 0\/1 Running 2 (55m ago) 2d1h 192.168.146.131 localhost.localdomain &lt;none&gt; &lt;none&gt;<\/em><br \/>\n<em>kube-system calico-node-dwldq 0\/1 Running 3 (56m ago) 2d12h 192.168.146.130 kubworker01 &lt;none&gt; &lt;none&gt;<\/em><br \/>\n<em>===== ===<\/em><\/p>\n<p>The &#8220;-o wide&#8221; option in the above command provides additional details of the pods, compared to the previous command.<\/p>\n<p>The below command provided information about the context presently used when accessing th<\/p>\n<p><strong>[root@kubmaster01 ~]#<\/strong> kubectl config current-context<\/p>\n<p><em>======<\/em><br \/>\n<em>kubernetes-admin@kubernetes<\/em><br \/>\n<em>=======<\/em><\/p>\n<p>The below command shows the different contexts that are presently available. On a newly installed cluster, only one will be available.<\/p>\n<p><strong>[root@kubmaster01 ~]#<\/strong> kubectl config get-contexts<\/p>\n<p><em>=====<\/em><br \/>\n<em> CURRENT NAME CLUSTER AUTHINFO NAMESPACE<\/em><br \/>\n<em> * kubernetes-admin@kubernetes kubernetes kubernetes-admin<\/em><br \/>\n<em> ==========<\/em><\/p>\n<p>The below command lists the resources available in the system.<\/p>\n<p><strong>[root@kubmaster01 ~]#<\/strong> kubectl api-resources | head -n 5<\/p>\n<p><em>===========<\/em><br \/>\n<em><strong>NAME\u00a0 \u00a0 SHORTNAMES\u00a0 \u00a0 APIVERSION\u00a0 \u00a0 NAMESPACED\u00a0 \u00a0 KIND<\/strong><\/em><br \/>\n<em>bindings v1 true Binding<\/em><br \/>\n<em>componentstatuses cs v1 false ComponentStatus<\/em><br \/>\n<em>configmaps cm v1 true ConfigMap<\/em><br \/>\n<em>endpoints ep v1 true Endpoints<\/em><br \/>\n<em>====== ===<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>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. <a class=\"mh-excerpt-more\" href=\"http:\/\/shijuvarghese.com\/?p=1624\" title=\"Kubernetes: Basic commands\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":1784,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17,21,34,3,30],"tags":[],"class_list":["post-1624","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cluster","category-devops","category-kubernetes","category-linux","category-rhel-9"],"_links":{"self":[{"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/posts\/1624","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1624"}],"version-history":[{"count":12,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/posts\/1624\/revisions"}],"predecessor-version":[{"id":1835,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/posts\/1624\/revisions\/1835"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/media\/1784"}],"wp:attachment":[{"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1624"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1624"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1624"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}