{"id":6267,"date":"2019-07-26T18:21:04","date_gmt":"2019-07-26T18:21:04","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=6267"},"modified":"2021-11-16T11:14:12","modified_gmt":"2021-11-16T11:14:12","slug":"working-with-kubernetes-cluster-using-kubectl-part-1","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/working-with-kubernetes-cluster-using-kubectl-part-1\/","title":{"rendered":"Kubernetes Commands: kubectl get &#8211; Tutorials and Examples"},"content":{"rendered":"\n<p><strong>Listing and Inspecting your cluster, pods, services and more.<\/strong><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>kubectl cluster-info<\/p><\/blockquote>\n\n\n\n<p><strong>review status and roles<\/strong><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>kubectl get nodes<\/p><p><\/p><\/blockquote>\n\n\n\n<p><strong>Additional information about each node in the cluster. <\/strong><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>kubectl get nodes -o wide<\/p><\/blockquote>\n\n\n\n<p><strong>Let&#8217;s get a list of pods\u2026but there isn&#8217;t any running<\/strong><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>kubectl get pods<\/p><\/blockquote>\n\n\n\n<p><strong>True, but let&#8217;s get a list of system pods. A namespace is a way to group resources together.<\/strong><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>kubectl get pods &#8211;namespace kube-system<\/p><\/blockquote>\n\n\n\n<p><strong>Let&#8217;s get additional information about each pod. <\/strong><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>kubectl get pods &#8211;namespace kube-system -o wide<\/p><\/blockquote>\n\n\n\n<p><strong>Now let&#8217;s get a list of everything that&#8217;s running in all namespaces<\/strong><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>kubectl get all &#8211;all-namespaces | more<\/p><\/blockquote>\n\n\n\n<p>Let&#8217;s look at the headers in each column. Name, Alias\/shortnames, API Group (or where that resource is in the k8s API Path),<\/p>\n\n\n\n<p>Is the resource in a namespace, for example StorageClass issn&#8217;t and is available to all namespaces and finally Kind\u2026this is the object type.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>kubectl api-resources | head -n 10<\/p><\/blockquote>\n\n\n\n<p><strong>We can easily filter using group<\/strong><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>kubectl api-resources | grep pod<\/p><\/blockquote>\n\n\n\n<p><strong>Explain an indivdual resource in detail<\/strong><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>kubectl explain pod | more <br>kubectl explain pod.spec | more <br>kubectl explain pod.spec.containers | more<\/p><\/blockquote>\n\n\n\n<p><strong>You&#8217;ll soon find your favorite alias<\/strong><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p> kubectl get no <\/p><\/blockquote>\n\n\n\n<p>Let&#8217;s take a closer look at our nodes using Describe<\/p>\n\n\n\n<p><strong>Check out Name, Taints, Conditions, Addresses, System Info, Non-Terminated Pods, and Events<\/strong><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>kubectl describe nodes c1-master1<br> kubectl describe nodes c1-node1<\/p><\/blockquote>\n\n\n\n<p><strong>Ok, so now that we&#8217;re tired of typing commands out, let&#8217;s enable bash auto-complete of our kubectl commands<\/strong><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>sudo apt-get install bash-completion<br> echo &#8220;source &lt;(kubectl completion bash)&#8221; &gt;&gt; ~\/.bashrc<br> source ~\/.bashrc<br> kubectl g[tab][tab] po[tab][tab] &#8211;all[tab][tab]<br> kubectl -h | more<br> kubectl get -h | more<br> kubectl describe -h | more <\/p><\/blockquote>\n\n\n<div class=\"epyt-gallery\" data-currpage=\"1\" id=\"epyt_gallery_25429\"><iframe loading=\"lazy\"  id=\"_ytid_97376\"  width=\"760\" height=\"427\"  data-origwidth=\"760\" data-origheight=\"427\" src=\"https:\/\/www.youtube.com\/embed\/?enablejsapi=1&#038;autoplay=0&#038;cc_load_policy=0&#038;cc_lang_pref=&#038;iv_load_policy=1&#038;loop=0&#038;rel=1&#038;fs=1&#038;playsinline=0&#038;autohide=2&#038;theme=dark&#038;color=red&#038;controls=1&#038;disablekb=0&#038;\" class=\"__youtube_prefs__  no-lazyload\" title=\"YouTube player\"  data-epytgalleryid=\"epyt_gallery_25429\"  allow=\"fullscreen; accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen data-no-lazy=\"1\" data-skipgform_ajax_framebjll=\"\"><\/iframe><div class=\"epyt-gallery-list\"><div>Sorry, there was a YouTube error.<\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>Listing and Inspecting your cluster, pods, services and more. kubectl cluster-info review status and roles kubectl get nodes Additional information about each node in the cluster. kubectl get nodes -o&#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[4859],"tags":[],"class_list":["post-6267","post","type-post","status-publish","format-standard","hentry","category-kubernetes"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/6267","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=6267"}],"version-history":[{"count":5,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/6267\/revisions"}],"predecessor-version":[{"id":25485,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/6267\/revisions\/25485"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=6267"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=6267"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=6267"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}