<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: 🐱 </title>
    <description>The latest articles on DEV Community by 🐱  (@okf).</description>
    <link>https://dev.to/okf</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F550105%2F22bff61d-46fb-4982-b4dc-69294da1b8da.jpeg</url>
      <title>DEV Community: 🐱 </title>
      <link>https://dev.to/okf</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/okf"/>
    <language>en</language>
    <item>
      <title>Quick Guide: Kubens, Kubectx, &amp; Stern</title>
      <dc:creator>🐱 </dc:creator>
      <pubDate>Wed, 30 Dec 2020 20:30:43 +0000</pubDate>
      <link>https://dev.to/okf/quick-guide-kubens-kubectx-stern-243</link>
      <guid>https://dev.to/okf/quick-guide-kubens-kubectx-stern-243</guid>
      <description>&lt;p&gt;These easily accessible Command Line Tools are fantastic for debugging and utilizing Kubernetes (&lt;strong&gt;k8s&lt;/strong&gt;) cloud resources from the command line.&lt;/p&gt;

&lt;h2&gt;
  
  
  Who is this for?
&lt;/h2&gt;

&lt;p&gt;This guide is coming from the perspective of someone trying to operate, develop and debug applications that are hosted via k8s. As someone who does this on a daily basis, I have come to appreciate a few wonderful tools that make the process much easier. &lt;/p&gt;

&lt;p&gt;The usefulness of each tool scales nicely with the level of infrastructure present within your organization. Those that are without multiple &lt;a href="https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/"&gt;namespaces&lt;/a&gt; and/or &lt;a href="https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/#context"&gt;contexts&lt;/a&gt; might not be served as well, but might still benefit from the knowledge of their existence.&lt;/p&gt;

&lt;p&gt;We would like to reduce&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;kubectl config set-context &amp;lt;insert-context-here&amp;gt; &lt;span class="nt"&gt;--namespace&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&amp;lt;insert-namespace-name-here&amp;gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;kubectl get pods | &amp;lt;tool-of-choice-to-extract-pod-list&amp;gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;kubectl log &lt;span class="nt"&gt;-f&lt;/span&gt; &amp;lt;pod-1&amp;gt; &amp;amp; kubectl log &lt;span class="nt"&gt;-f&lt;/span&gt; &amp;lt;pod-2&amp;gt; &amp;amp; ...kubectl log &lt;span class="nt"&gt;-f&lt;/span&gt; &amp;lt;pod-N&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;down to something much more manageable, with low cognitive performance.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Aside&lt;/strong&gt;: &lt;a href="https://stackoverflow.com/questions/61171487/what-is-the-difference-between-namespaces-and-contexts-in-kubernetes#:~:text=Namespace%20is%20a%20logical%20partition,to%20manage%20resources%20and%20constraints.&amp;amp;text=A%20context%20in%20Kubernetes%20is,a%20user%2C%20and%20a%20namespace."&gt;Context vs namespaces&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting Started
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Prerequisites:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.redhat.com/en/topics/cloud-computing/what-are-cloud-providers"&gt;A Cloud Service Provider + k8s&lt;/a&gt;.

&lt;ul&gt;
&lt;li&gt;The target for most of this guide, if you are not actively utilizing some form of k8s, this will not be useful for you.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://kubernetes.io/docs/tasks/tools/install-kubectl/"&gt;Kubectl&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Installation
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://github.com/ahmetb/kubectx#installation"&gt;Install Kubectx + Kubens&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/wercker/stern"&gt;Install Stern&lt;/a&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Usage
&lt;/h2&gt;

&lt;p&gt;Switch k8s &lt;strong&gt;contexts&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;kubectx &amp;lt;context_name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Switch k8s &lt;strong&gt;namespace&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;kubens &amp;lt;namespace_name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Tail&lt;/strong&gt; pods.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;stern &amp;lt;pod_name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Often we'll find ourselves trying to debug a specific container within our pods. This might be due to a split in services across the pod. We can do&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;stern &lt;span class="nt"&gt;--container&lt;/span&gt; &amp;lt;container-name&amp;gt; &amp;lt;pod-name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Voilà, we have significantly reduced our cognitive load and made switching contexts in our shell of choice much easier. We could take this a step further and alias out these commands, but I'll leave that to the reader. As they stand these are suitable for much quicker debugging sessions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Aside&lt;/strong&gt;: Making life even easier with &lt;a href="https://github.com/ahmetb/kubectl-aliases"&gt;Kubectl-aliases&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thank you for reading, and have a wonderful day 😊 💕  &lt;/p&gt;

</description>
      <category>kubernetes</category>
      <category>cloud</category>
    </item>
  </channel>
</rss>
