<?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: Florian Lacrampe</title>
    <description>The latest articles on DEV Community by Florian Lacrampe (@quadeare).</description>
    <link>https://dev.to/quadeare</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%2F723331%2Fcee3067f-8cce-411c-ab3f-f2baa9b95f93.jpeg</url>
      <title>DEV Community: Florian Lacrampe</title>
      <link>https://dev.to/quadeare</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/quadeare"/>
    <language>en</language>
    <item>
      <title>Gitpod : How to use kubectl and manage Kubernetes clusters ?</title>
      <dc:creator>Florian Lacrampe</dc:creator>
      <pubDate>Wed, 13 Oct 2021 13:00:57 +0000</pubDate>
      <link>https://dev.to/stack-labs/gitpod-how-to-use-kubectl-and-manage-kubernetes-clusters--4edp</link>
      <guid>https://dev.to/stack-labs/gitpod-how-to-use-kubectl-and-manage-kubernetes-clusters--4edp</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://gitpod.io" rel="noopener noreferrer"&gt;Gitpod&lt;/a&gt; is a Ready-to-Code development platform which allow users to quickly contribute on projects. This platform is powered by VS-Code online.&lt;/p&gt;

&lt;p&gt;GitOps is now a standard approach to manage applications and infrastructure delivery. Gitpod is very usefull for that, because you can offer to anyone a Ready-to-Use platform to administrate and contribute.&lt;/p&gt;

&lt;p&gt;Gitpod simplifying project startup ! All the tools you use will be available in the VS-Code terminal.&lt;/p&gt;

&lt;p&gt;Here, i will share my experience with Gitpod to administrate and contribute on Kubernetes projects.&lt;/p&gt;

&lt;h2&gt;
  
  
  Requirements
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Gitpod account on gitpod.io (Or self-hosted instance)&lt;/li&gt;
&lt;li&gt;Gitlab / Github account (or private Git server)&lt;/li&gt;
&lt;li&gt;Working Kubernetes cluster&lt;/li&gt;
&lt;li&gt;A web browser !&lt;/li&gt;
&lt;/ul&gt;

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

&lt;h3&gt;
  
  
  1. Init git project
&lt;/h3&gt;

&lt;p&gt;First, you need to create en empty git project and open it with Gitpod.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Tips: You can install web-browser extension to quickly open git projects with Gitpod : &lt;a href="https://www.gitpod.io/docs/browser-extension/" rel="noopener noreferrer"&gt;https://www.gitpod.io/docs/browser-extension/&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  2. Set up .gitpod.yml
&lt;/h3&gt;

&lt;p&gt;Gitpod allow user to specify environments settings like :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Environment Docker image&lt;/li&gt;
&lt;li&gt;VS-Code extensions&lt;/li&gt;
&lt;li&gt;Startup tasks&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here, we want to manage and administrate a Kubernetes cluster. &lt;/p&gt;

&lt;p&gt;Unfortunately, official Gitpod environment image does not contain Kubernetes administration tools (kubectl, Helm, Kustomize etc..).&lt;/p&gt;

&lt;p&gt;So, we going to change default image to use a custom image with all needed tools.&lt;/p&gt;

&lt;h4&gt;
  
  
  Use image from Docker Hub (Easy method !)
&lt;/h4&gt;

&lt;p&gt;I recently publish a Docker image with useful tools to manage Kubernetes cluster through Gitpod.&lt;/p&gt;

&lt;p&gt;Project : &lt;a href="https://github.com/quadeare/gitpod-kubectl" rel="noopener noreferrer"&gt;https://github.com/quadeare/gitpod-kubectl&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can test this Gitpod environement by opening this project with Gitpod :&lt;br&gt;
&lt;a href="https://gitpod.io/#https://gitlab.com/quadeare/gitpod-kubectl.git" rel="noopener noreferrer"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgitpod.io%2Fbutton%2Fopen-in-gitpod.svg" alt="Open in Gitpod" width="160" height="45"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Create a &lt;code&gt;.gitpod.yml&lt;/code&gt; file and copy the following content :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;image: quadeare/gitpod-kubectl:latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After that, commit and push &lt;code&gt;.gitpod.yml&lt;/code&gt;. Then, restart Gitpod workspace (close and open).&lt;/p&gt;

&lt;h4&gt;
  
  
  Use local Dockerfile (Take control !)
&lt;/h4&gt;

&lt;p&gt;You can also build you own Docker image (by using Gitpod) and remain self-sufficient without having to depend on an external image.&lt;/p&gt;

&lt;p&gt;So, you can create a simple .gitpod.yml file with the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;image:
  file: .gitpod.Dockerfile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, create .gitpod.Dockerfile like that :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM gitpod/workspace-base:latest

ARG KUBECTL_VERSION=v1.22.2

RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/${KUBECTL_VERSION}/bin/linux/amd64/kubectl &amp;amp;&amp;amp; \
    chmod +x ./kubectl &amp;amp;&amp;amp; \
    sudo mv ./kubectl /usr/local/bin/kubectl &amp;amp;&amp;amp; \
    mkdir ~/.kube

RUN set -x; cd "$(mktemp -d)" &amp;amp;&amp;amp; \
    OS="$(uname | tr '[:upper:]' '[:lower:]')" &amp;amp;&amp;amp; \
    ARCH="$(uname -m | sed -e 's/x86_64/amd64/' -e 's/\(arm\)\(64\)\?.*/\1\2/' -e 's/aarch64$/arm64/')" &amp;amp;&amp;amp; \
    curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/krew.tar.gz" &amp;amp;&amp;amp; \
    tar zxvf krew.tar.gz &amp;amp;&amp;amp; \
    KREW=./krew-"${OS}_${ARCH}" &amp;amp;&amp;amp; \
    "$KREW" install krew &amp;amp;&amp;amp; \
    echo 'export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"' &amp;gt;&amp;gt; /home/gitpod/.bashrc

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After that, commit and push &lt;code&gt;.gitpod.yml&lt;/code&gt;/&lt;code&gt;.gitpod.Dockerfile&lt;/code&gt;. Then, restart Gitpod workspace (close and open).&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Add your kubeconfig as Gitpod secret
&lt;/h3&gt;

&lt;p&gt;To administrate your Kubernetes cluster from Gitpod, you need to add Kubeconfig content as secret on Gitpod.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Gitpod supports encrypted, user-specific environment variables. They are stored as part of your user settings and can be used to set access tokens, or pass any other kind of user-specific information to your workspaces.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  Convert Kubeconfig to base64
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cat kubeconfig | base64 -w 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Copy Kubeconfig (base64 format) to Gitpod
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwzlxjinkjvqygure9wht.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwzlxjinkjvqygure9wht.png" alt="image" width="800" height="171"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5nj798iufhgpw4nct3oq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5nj798iufhgpw4nct3oq.png" alt="image" width="502" height="467"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You can add multiple kubeconfig secrets with same variable name (ex : K8S_CTX) by using project scope !&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7aa28kiz2pb0rfxla4cb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7aa28kiz2pb0rfxla4cb.png" alt="image" width="800" height="318"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;h3&gt;
  
  
  4. Configure your project to extract kubeconfig
&lt;/h3&gt;

&lt;p&gt;Now, edit your &lt;code&gt;.gitpod.yml&lt;/code&gt; file and add this following content :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;tasks:
  - name: Set Glados K8s context
    command: echo $K8S_CTX | base64 -d &amp;gt; ~/.kube/config
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After that, commit and push &lt;code&gt;.gitpod.yml&lt;/code&gt;. Then, restart Gitpod workspace (close and open).&lt;/p&gt;

&lt;p&gt;Now, you should be able to administrate your Kubernetes cluster with Kubectl, Helm or even with VS-Code by using Kubernetes extension.&lt;/p&gt;

&lt;h4&gt;
  
  
  Kubectl and Helm commands
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fotxn0m616uheq44r1x3o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fotxn0m616uheq44r1x3o.png" alt="image" width="800" height="216"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  VS-Code Kubernetes extension
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdp1uynfrrrdwpw9kvqxx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdp1uynfrrrdwpw9kvqxx.png" alt="image" width="368" height="465"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Gitpod can be very useful to quickly get a handle on Kubernetes clusters without having to install all tools (Kubectl, Krew plugins, Kustomize etc..).&lt;/p&gt;

&lt;p&gt;However, it may be necessary to ask security question :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Are Gitpod secrets really secured ?&lt;/li&gt;
&lt;li&gt;Are Gitpod workspace perfectly isolated ?&lt;/li&gt;
&lt;li&gt;Is it reasonable to put kubernetes cluster connection informations on Gitpod?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In my case, i prefer to install self-hosted Gitpod to keep my secrets/workspaces in secure place, but that may not be enough.&lt;/p&gt;

&lt;p&gt;Moreover, it should not replace an automation by continuous integration. It's very convenient to talk directly to a Kubernetes cluster, but Gitpod should not become a Kubernetes deployment solution. It should be used only for troobleshooting or testing.&lt;/p&gt;

</description>
      <category>kubernetes</category>
      <category>gitpod</category>
      <category>docker</category>
      <category>productivity</category>
    </item>
  </channel>
</rss>
