<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Barun Debnath]]></title><description><![CDATA[Barun Debnath]]></description><link>https://heybarun.hashnode.dev</link><image><url>https://cdn.hashnode.com/res/hashnode/image/upload/v1685197797984/qFZHi3Gho.png</url><title>Barun Debnath</title><link>https://heybarun.hashnode.dev</link></image><generator>RSS for Node</generator><lastBuildDate>Mon, 21 Sep 2026 04:07:50 GMT</lastBuildDate><atom:link href="https://heybarun.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[01. Setting up Docker, gcloud, kubectl, minikube, and GKE on GCP Virtual Machine]]></title><description><![CDATA[Before starting the tutorial, make sure you have an active GCP (Google Cloud Provider) account

GCP provides 300$ of credits for free for the first three months.

Sign up to GCP using your credit or debit card.

Even after three months, you won't be ...]]></description><link>https://heybarun.hashnode.dev/01-setting-up-docker-gcloud-kubectl-minikube-and-gke-on-gcp-virtual-machine</link><guid isPermaLink="true">https://heybarun.hashnode.dev/01-setting-up-docker-gcloud-kubectl-minikube-and-gke-on-gcp-virtual-machine</guid><category><![CDATA[Docker]]></category><category><![CDATA[GCP]]></category><category><![CDATA[Devops]]></category><category><![CDATA[Devops articles]]></category><category><![CDATA[minikube]]></category><dc:creator><![CDATA[Barun Debnath]]></dc:creator><pubDate>Sun, 19 Nov 2023 18:39:47 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1700419107200/aa30ac83-247f-46d3-bd27-f5cf0f46dec8.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<ul>
<li><p>Before starting the tutorial, make sure you have an active GCP (Google Cloud Provider) account</p>
<ul>
<li><p>GCP provides <code>300</code>$ of credits for free for the first three months.</p>
</li>
<li><p>Sign up to GCP using your credit or debit card.</p>
</li>
<li><p>Even after three months, you won't be charged unless you have manually activated the account.</p>
</li>
</ul>
</li>
</ul>
<hr />
<h1 id="heading-create-a-vm-virtual-machine">Create a VM (Virtual Machine)</h1>
<ol>
<li><p>Click on <code>Compute Engine</code></p>
</li>
<li><p>Enable <code>Compute Engine</code> API. It will take a minute or so!</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1700069737896/7fe2807c-3f92-4ed5-a87d-3e4fb3578a54.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Click on <code>Create Instance</code></p>
</li>
<li><p>Give name, region and machine type of your choice.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1700069879592/c189449b-4b07-4699-a8f0-70bbfbd43841.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>On <code>boot disk</code>, click on <code>Change</code></p>
<ul>
<li><p>We will use <code>Ubuntu</code> image with 100 GB boot disk.</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1700069949613/393e4c3f-915a-4be7-ab8d-913e1a89bb6c.png" alt class="image--center mx-auto" /></p>
</li>
</ul>
</li>
<li><p>Give full access to all Cloud APIs and allow HTTP/s traffic.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1700070026022/38ca70f0-d6e0-4e3a-86f4-309903ea665a.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Click on <code>Create</code></p>
<ul>
<li>It will take a couple of minutes to create the VM.</li>
</ul>
</li>
</ol>
<hr />
<h1 id="heading-accessing-vm-using-ssh-keys">Accessing VM using SSH keys</h1>
<ul>
<li><p>GCP VMs can be accessed using a browser window too, but it's not efficient.</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1700070170810/7e06321e-1971-4567-a551-25f6c743a27e.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>We are going to use a more traditional and efficient method to access and exec into a VM, i.e. using SSH keys.</p>
</li>
</ul>
<h2 id="heading-steps">Steps</h2>
<h3 id="heading-generating-ssh-keys">Generating SSH Keys</h3>
<ol>
<li><p>Generate SSH Keys : <code>ssh-keygen -b 2048 -t rsa</code></p>
<ul>
<li><p><code>-b 2048</code> - is optional. It says that the length of the key should be 2048 bytes.</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1700071097481/44bc36cf-4b1f-4346-808d-e86c4b691a2d.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>You can give a custom name for your key</p>
</li>
<li><p>If you want you can keep the paraphrase empty.</p>
</li>
</ul>
</li>
<li><p>Now, go to the search bar, and type <code>SSH</code></p>
<ul>
<li>Select the SSH option which has <code>Compute Engine</code> as its category.</li>
</ul>
</li>
<li><p>Click <code>Add SSH Key</code></p>
</li>
<li><p>Copy the <code>.pub</code> key file content.</p>
<ul>
<li>You can use <code>cat</code> command - <code>cat test.pub</code></li>
</ul>
</li>
<li><p>Paste the content in the input.</p>
</li>
<li><p>Click on <code>Save</code></p>
</li>
</ol>
<h3 id="heading-connecting-to-vm">Connecting to VM</h3>
<ol>
<li><p>Now open up your terminal.</p>
</li>
<li><p>Copy the external IP of your VM instance.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1700073747327/c97aed93-a53f-4c76-a4c8-f724f278029a.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Now on your terminal, enter the following command:</p>
<pre><code class="lang-bash"> ssh username@IP_ADDRESS -i ./location_of_your_private_key
</code></pre>
<ul>
<li><p>username can be found in your public SSH key</p>
</li>
<li><p>SSH Private key is the file without any extension, in my case - <code>test</code></p>
</li>
</ul>
</li>
<li><p>Click Enter.</p>
</li>
<li><p>Type <code>yes,</code> when asked for it.</p>
</li>
<li><p>Now you are successfully able to access your VM.</p>
</li>
</ol>
<h3 id="heading-connecting-via-vscode">Connecting via VSCode</h3>
<ul>
<li><p>VSCode has an extension which enables us to connect your VSCode Editor to the VM instance.</p>
<ul>
<li>It helps us to navigate files and folders very easily and frequently.</li>
</ul>
</li>
<li><p><strong>Install the below extensions:</strong></p>
<ol>
<li><p><strong>Remote SSH - by Microsoft</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1700074212703/15814b1f-4c46-4d7d-981c-05e8da8d209d.png" alt class="image--center mx-auto" /></p>
</li>
<li><p><strong>Remote - SSH: Editing Configuration Files</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1700074276631/7d441ff1-d0e9-4980-8d81-cfcc65691e7b.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Click <code>Ctrl + Shift + P</code></p>
</li>
<li><p>Type <code>SSH</code> and select <code>Remote - SSH: Add New Host</code></p>
</li>
<li><p>Enter the SSH command as given in the above section.</p>
<ul>
<li>Select the config location where you want to store your config.</li>
</ul>
</li>
<li><p>Again press <code>Ctrl + Shift + P</code>, and type <code>SSH</code></p>
</li>
<li><p>Select <code>Remote - SSH: Connect to Host</code></p>
</li>
<li><p>Select the IP of the VM you want to connect to.</p>
</li>
<li><p>Now your VSCode is connected to your VM.</p>
</li>
</ol>
</li>
</ul>
<hr />
<h1 id="heading-installing-docker">Installing Docker</h1>
<ol>
<li><p>First, run the below commands to upgrade and update local dependencies:</p>
<pre><code class="lang-bash"> sudo apt-get upgrade
 sudo apt-get update
</code></pre>
</li>
<li><p>If you want to install Vim or Neovim as text editor, run below command (Optional)</p>
<pre><code class="lang-bash"> sudo apt-get install neovim
</code></pre>
</li>
<li><p><strong>Now follow the installation steps here -</strong> <a target="_blank" href="https://docs.docker.com/engine/install/ubuntu/"><strong>Official Docs Link</strong></a></p>
<ol>
<li><p>Run this command to remove old installation packages and files</p>
<pre><code class="lang-bash"> <span class="hljs-keyword">for</span> pkg <span class="hljs-keyword">in</span> docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; <span class="hljs-keyword">do</span> sudo apt-get remove <span class="hljs-variable">$pkg</span>; <span class="hljs-keyword">done</span>
</code></pre>
</li>
<li><p>Installing using <code>apt</code> repository:</p>
<ol>
<li><p>Setup <code>Docker's</code> apt repository:</p>
<pre><code class="lang-bash"> <span class="hljs-comment"># Add Docker's official GPG key:</span>
 sudo apt-get update
 sudo apt-get install ca-certificates curl gnupg
 sudo install -m 0755 -d /etc/apt/keyrings
 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
 sudo chmod a+r /etc/apt/keyrings/docker.gpg

 <span class="hljs-comment"># Add the repository to Apt sources:</span>
 <span class="hljs-built_in">echo</span> \
   <span class="hljs-string">"deb [arch="</span>$(dpkg --print-architecture)<span class="hljs-string">" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
   "</span>$(. /etc/os-release &amp;&amp; <span class="hljs-built_in">echo</span> <span class="hljs-string">"<span class="hljs-variable">$VERSION_CODENAME</span>"</span>)<span class="hljs-string">" stable"</span> | \
   sudo tee /etc/apt/sources.list.d/docker.list &gt; /dev/null
 sudo apt-get update
</code></pre>
</li>
<li><p>Install Docker packages:</p>
<pre><code class="lang-bash"> sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
</code></pre>
</li>
<li><p>Verify the Docker-Engine installation</p>
<pre><code class="lang-bash"> sudo docker run hello-world
</code></pre>
</li>
</ol>
</li>
<li><p>Other ways to install docker:</p>
<ol>
<li><p>Installing from a package - <a target="_blank" href="https://docs.docker.com/engine/install/ubuntu/#install-from-a-package">Link</a></p>
</li>
<li><p>Installing using convenience script - <a target="_blank" href="https://docs.docker.com/engine/install/ubuntu/#install-using-the-convenience-script">Link</a></p>
</li>
</ol>
</li>
<li><p>Uninstall docker - <a target="_blank" href="https://docs.docker.com/engine/install/ubuntu/#uninstall-docker-engine">Link</a></p>
</li>
</ol>
</li>
<li><p><strong>Post Installation Steps</strong></p>
<ul>
<li><p>Docker daemon binds to a Unix socket and not a TCP port.</p>
</li>
<li><p>By default, it is accessed by <code>sudo</code></p>
</li>
<li><p>If you don't want to use the <code>docker</code> command with <code>sudo</code>, create a Unix group called <code>docker</code> and add users to it.</p>
</li>
<li><p><strong>Steps:</strong></p>
<ol>
<li><p>Run below commands:</p>
<ul>
<li>First create a group <code>docker</code> and then add a <code>USER</code> to it</li>
</ul>
</li>
</ol>
</li>
</ul>
</li>
</ol>
<pre><code class="lang-bash">            sudo groupadd docker
            sudo usermod -aG docker <span class="hljs-variable">$USER</span>
</code></pre>
<ol>
<li><p>Now log out and log in back to evaluate your group membership <strong>OR</strong></p>
<p> Run the following:</p>
<pre><code class="lang-bash"> newgrp docker
</code></pre>
</li>
<li><p>Verify whether <code>docker</code> runs without <code>sudo</code> or not:</p>
<pre><code class="lang-bash"> docker run hello-world
</code></pre>
</li>
<li><p>Configure Docker to start on boot with systemd</p>
<pre><code class="lang-bash"> sudo systemctl <span class="hljs-built_in">enable</span> docker.service
 sudo systemctl <span class="hljs-built_in">enable</span> containerd.service
</code></pre>
</li>
<li><p>For more, follow this doc - <a target="_blank" href="https://docs.docker.com/engine/install/linux-postinstall/#configure-docker-to-start-on-boot-with-systemd">Link</a></p>
</li>
</ol>
<hr />
<h1 id="heading-installing-gcloud-cli">Installing <code>gcloud</code> CLI</h1>
<ul>
<li><p>We have to install <code>gcloud</code> CLI to interact with GKE clusters.</p>
</li>
<li><p>I am following this doc - <strong>Link</strong></p>
</li>
<li><p><strong>Steps:</strong></p>
<ol>
<li><p>Run the below commands and install the required dependencies:</p>
<pre><code class="lang-bash"> sudo apt-get update
 sudo apt-get install apt-transport-https ca-certificates gnupg curl sudo
</code></pre>
</li>
<li><p>Add the gcloud CLI distribution URI as a package source.</p>
<pre><code class="lang-bash"> <span class="hljs-built_in">echo</span> <span class="hljs-string">"deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main"</span> | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
</code></pre>
</li>
<li><p>Import Google Cloud Public Key</p>
<pre><code class="lang-bash"> curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add -
</code></pre>
</li>
<li><p>Update and install gcloud CLI:</p>
<pre><code class="lang-bash"> sudo apt-get update &amp;&amp; sudo apt-get install google-cloud-cli
</code></pre>
</li>
</ol>
</li>
<li><p><strong>Note:</strong></p>
<ul>
<li><p>If facing error</p>
<blockquote>
<p>Conflicting values set for option Signed-By regarding source <a target="_blank" href="https://packages.cloud.google.com/apt/">https://packages.cloud.google.com/apt/</a> cloud-sdk: /usr/share/keyrings/<a target="_blank" href="http://cloud.google">cloud.google</a>.asc !=</p>
<p>E: The list of sources could not be read.</p>
</blockquote>
<ul>
<li><p>RUN:</p>
<pre><code class="lang-bash">  <span class="hljs-built_in">cd</span> /etc/apt/sources.list.d
  sudo rm google-cloud-sdk.list
</code></pre>
</li>
<li><p>Then apply the above steps again.</p>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<ol>
<li><p>Run <code>gcloud init</code></p>
<ul>
<li><p>Select <code>Log in with a new account</code></p>
</li>
<li><p>Open the link in your browser.</p>
<ul>
<li><p>Sign up with the Google account that you used for your GCP account</p>
</li>
<li><p>Copy the authorization code and paste it into the terminal.</p>
</li>
<li><p>Select the project you want to work with.</p>
</li>
<li><p>Enter <code>n</code> for configuring default Compute Region and Zone.</p>
</li>
</ul>
</li>
</ul>
</li>
</ol>
<hr />
<h1 id="heading-installing-kubectl">Installing <code>kubectl</code></h1>
<ul>
<li><p>Follow this doc to install in <code>kubectl</code> in Linux</p>
</li>
<li><p><strong>Steps:</strong></p>
<ol>
<li><p>Run the below command to download latest release</p>
<pre><code class="lang-bash">    curl -LO <span class="hljs-string">"https://dl.k8s.io/release/<span class="hljs-subst">$(curl -L -s https://dl.k8s.io/release/stable.txt)</span>/bin/linux/amd64/kubectl"</span>
</code></pre>
</li>
<li><p>Validate binary:</p>
<pre><code class="lang-bash"> curl -LO <span class="hljs-string">"https://dl.k8s.io/release/<span class="hljs-subst">$(curl -L -s https://dl.k8s.io/release/stable.txt)</span>/bin/linux/amd64/kubectl.sha256"</span>
 <span class="hljs-built_in">echo</span> <span class="hljs-string">"<span class="hljs-subst">$(cat kubectl.sha256)</span>  kubectl"</span> | sha256sum --check
</code></pre>
<ul>
<li><p>If valid, the output is:</p>
<pre><code class="lang-bash">  kubectl: OK
</code></pre>
</li>
</ul>
</li>
<li><p>Install kubectl</p>
<pre><code class="lang-bash"> sudo install -o root -g root -m 0755 kubectl /usr/<span class="hljs-built_in">local</span>/bin/kubectl
</code></pre>
</li>
<li><p>Test <code>kubectl</code></p>
<pre><code class="lang-bash"> kubectl version --client
</code></pre>
</li>
</ol>
</li>
</ul>
<hr />
<h1 id="heading-installing-minikube">Installing <code>minikube</code></h1>
<blockquote>
<p>Minikube is local Kubernetes, focusing on making it easy to learn and develop for Kubernetes.</p>
</blockquote>
<ul>
<li>Follow this doc: <a target="_blank" href="https://minikube.sigs.k8s.io/docs/start/">Link</a></li>
</ul>
<ul>
<li><p><strong>Steps:</strong></p>
<ol>
<li><p>Run the following commands:</p>
<pre><code class="lang-bash"> curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube_latest_amd64.deb
 sudo dpkg -i minikube_latest_amd64.deb
 minikube start
</code></pre>
</li>
<li><p>Interact with your cluster:</p>
<pre><code class="lang-bash"> kubectl get po -A
 minikube kubectl -- get po -A
 <span class="hljs-built_in">alias</span> kubectl=<span class="hljs-string">"minikube kubectl --"</span>
 minikube dashboard
</code></pre>
</li>
<li><p>Opening dashboard in your local machine:</p>
<pre><code class="lang-bash"> ssh  -L 42767:localhost:42767 USERNAME@EXTERNAL_IP_ADDRESS -i ~/location_of_private_key/
</code></pre>
</li>
<li><p>Open the dashboard in your local machine:</p>
<blockquote>
<p><a target="_blank" href="http://127.0.0.1:42767/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/#/deployment?namespace=default">http://127.0.0.1:42767/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/#/deployment?namespace=default</a></p>
</blockquote>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1700415282391/c1eaab75-3290-42e3-b789-18f75b816d20.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Enable ingress:</p>
<pre><code class="lang-bash"> minikube addons <span class="hljs-built_in">enable</span> ingress
</code></pre>
</li>
<li><p>Stop and delete all minikube clusters:</p>
<pre><code class="lang-bash"> minikube stop
 minikube delete --all
</code></pre>
</li>
</ol>
</li>
</ul>
<hr />
<h1 id="heading-setting-up-gke-using-ui">Setting up GKE (Using UI)</h1>
<ol>
<li><p>Go to GCP console.</p>
</li>
<li><p>Click on <code>Kubernetes Engine</code></p>
<ol>
<li><code>Enable</code> Kubernetes Engine API</li>
</ol>
</li>
<li><p>Click on <code>Create</code></p>
</li>
<li><p>Click on <code>Switch to Standard Cluster</code></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1700416336366/7e341619-f1c6-48e4-8efd-dabbd68fa131.png" alt class="image--center mx-auto" /></p>
</li>
<li><p><strong>In</strong> <code>Cluster Basics</code> <strong>, enter the details as you require.</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1700416651898/1e22752b-781b-4f28-b814-177075e5a33a.png" alt class="image--center mx-auto" /></p>
</li>
<li><p><strong>Click on</strong> <code>default-pool</code> <strong>and enter the number of nodes as</strong> <code>3</code></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1700416712951/8ac090ac-878d-451d-a678-9f0d74d1b425.png" alt class="image--center mx-auto" /></p>
<ul>
<li><p>Enable the cluster autoscaler.</p>
</li>
<li><p>Add a minimum number of nodes as 0 or 1 (up to you) and a maximum as 3.</p>
</li>
</ul>
</li>
<li><p><strong>Click on</strong> <code>Nodes</code> <strong>option under</strong> <code>default-pool</code></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1700416989135/d6b12709-3a48-4810-bef5-3ea8a28041f8.png" alt class="image--center mx-auto" /></p>
<ul>
<li><p>Select image type as <code>Ubuntu with containerd (ubuntu_containerd)</code></p>
</li>
<li><p>Select machine type as per your requirement.</p>
</li>
<li><p>Click on <code>Create</code></p>
</li>
</ul>
</li>
<li><p>It will take around 5 mins (or more) to create a GKE cluster.</p>
</li>
<li><p>Click on <code>Connect</code> and copy the <code>gcloud</code> command</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1700417942788/d39c96c4-b936-49f7-8c32-549d28fc16ef.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Open the terminal and SSH into the VM.</p>
</li>
<li><p>For kubectl to work with GKE, we need to install <code>google-cloud-sdk-gke-gcloud-auth-plugin</code></p>
<pre><code class="lang-bash">sudo apt-get install google-cloud-sdk-gke-gcloud-auth-plugin
</code></pre>
</li>
<li><p>Now paste the command you copied from GKE cluster</p>
</li>
<li><p>Check if the cluster can be accessed from local <code>kubectl</code> CLI</p>
<pre><code class="lang-bash">kubectl get ns
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1700418322127/ef31c203-0deb-485d-ba5e-12922c8ab270.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Delete the cluster using GUI itself.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1700418472288/74cb183a-2478-43ae-be58-f6978051df3b.png" alt class="image--center mx-auto" /></p>
</li>
</ol>
<hr />
<h1 id="heading-conclusion">Conclusion</h1>
<ul>
<li><p>In this tutorial, we have seen how to create a GCP VM instance and set up docker, GKE, kubectl and minikube.</p>
</li>
<li><p>In the next article we are gonna see how to create a GKE cluster using Terraform.</p>
</li>
</ul>
]]></content:encoded></item></channel></rss>