<?xml version="1.0" encoding="UTF-8"?>
<rss  xmlns:atom="http://www.w3.org/2005/Atom" 
      xmlns:media="http://search.yahoo.com/mrss/" 
      xmlns:content="http://purl.org/rss/1.0/modules/content/" 
      xmlns:dc="http://purl.org/dc/elements/1.1/" 
      version="2.0">
<channel>
<title>annq.io.vn</title>
<link>https://annq.io.vn/</link>
<atom:link href="https://annq.io.vn/index.xml" rel="self" type="application/rss+xml"/>
<description>A personal website for blogging</description>
<generator>quarto-1.9.37</generator>
<lastBuildDate>Wed, 10 Apr 2024 00:00:00 GMT</lastBuildDate>
<item>
  <title>Install Kubernetes Cluster on Ubuntu Server 22.04</title>
  <dc:creator>Quoc-An Nguyen</dc:creator>
  <link>https://annq.io.vn/posts/install-k8s-cluster/</link>
  <description><![CDATA[ 





<p>A note to setting up a Kubernetes cluster.</p>
<section id="prerequisites" class="level3">
<h3 class="anchored" data-anchor-id="prerequisites">Prerequisites</h3>
<ul>
<li>Three VMs running Ubuntu Server 22.04</li>
<li>Network connectivity between all nodes</li>
</ul>
<p>In this guide, I’m using VMware with NAT networking. Here are my node IP addresses:</p>
<ul>
<li><strong>k8s-master:</strong> 192.168.72.129</li>
<li><strong>k8s-worker1:</strong> 192.168.72.130</li>
<li><strong>k8s-worker2:</strong> 192.168.72.131</li>
</ul>
<blockquote class="blockquote">
<p>You can find your IP addresses by running <code>ip a</code> in each VM.</p>
</blockquote>
</section>
<section id="step-1-preparation" class="level3">
<h3 class="anchored" data-anchor-id="step-1-preparation">Step 1: Preparation</h3>
<section id="preparing-the-environment" class="level4">
<h4 class="anchored" data-anchor-id="preparing-the-environment">Preparing the Environment</h4>
<p>First, update all packages on each node:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sudo</span> apt update</span>
<span id="cb1-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sudo</span> apt upgrade <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-y</span></span></code></pre></div></div>
<p>Reboot to apply any kernel updates:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb2-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sudo</span> reboot</span></code></pre></div></div>
<p>Set up the hostnames for each node:</p>
<p>On the master node:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb3-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sudo</span> hostnamectl set-hostname <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"k8s-master.quocanuit.local"</span></span></code></pre></div></div>
<p>On worker1:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb4-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sudo</span> hostnamectl set-hostname <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"k8s-worker1.quocanuit.local"</span></span></code></pre></div></div>
<p>On worker2:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb5-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sudo</span> hostnamectl set-hostname <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"k8s-worker2.quocanuit.local"</span></span></code></pre></div></div>
</section>
<section id="modifying-etchosts-on-all-nodes" class="level4">
<h4 class="anchored" data-anchor-id="modifying-etchosts-on-all-nodes">Modifying <code>/etc/hosts</code> on All Nodes</h4>
<p>Edit the hosts file on each node:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb6-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sudo</span> nano /etc/hosts</span></code></pre></div></div>
<p>Add the following entries:</p>
<pre class="text"><code>192.168.72.129 k8s-master.quocanuit.local k8s-master
192.168.72.130 k8s-worker1.quocanuit.local k8s-worker1
192.168.72.131 k8s-worker2.quocanuit.local k8s-worker2</code></pre>
</section>
<section id="disabling-swap" class="level4">
<h4 class="anchored" data-anchor-id="disabling-swap">Disabling Swap</h4>
<p>Kubernetes requires swap to be disabled. On all nodes:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb8-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sudo</span> swapoff <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-a</span></span></code></pre></div></div>
<p>Verify that swap is disabled:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb9" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb9-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">free</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-h</span></span></code></pre></div></div>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://annq.io.vn/posts/install-k8s-cluster/dYu5CM9.png" class="img-fluid figure-img"></p>
<figcaption>free -h</figcaption>
</figure>
</div>
<p>To make this change permanent, edit <code>/etc/fstab</code>:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb10" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb10-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sudo</span> nano /etc/fstab</span></code></pre></div></div>
<p>Comment out the swap line:</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://annq.io.vn/posts/install-k8s-cluster/bQBVA1R.png" class="img-fluid figure-img"></p>
<figcaption>swap fstab</figcaption>
</figure>
</div>
<p>Apply the changes:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb11" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb11-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sudo</span> mount <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-a</span></span></code></pre></div></div>
</section>
<section id="configuring-kernel-settings" class="level4">
<h4 class="anchored" data-anchor-id="configuring-kernel-settings">Configuring Kernel Settings</h4>
<p>Load the necessary kernel modules:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb12" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb12-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sudo</span> tee /etc/modules-load.d/containerd.conf <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;&lt;EOF</span></span>
<span id="cb12-2"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">overlay</span></span>
<span id="cb12-3"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">br_netfilter</span></span>
<span id="cb12-4"><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">EOF</span></span></code></pre></div></div>
<p>Activate the modules:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb13" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb13-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sudo</span> modprobe overlay</span>
<span id="cb13-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sudo</span> modprobe br_netfilter</span></code></pre></div></div>
<p>Set kernel parameters for Kubernetes:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb14" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb14-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sudo</span> tee /etc/sysctl.d/kubernetes.conf <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;&lt;EOF</span></span>
<span id="cb14-2"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">net.bridge.bridge-nf-call-ip6tables = 1</span></span>
<span id="cb14-3"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">net.bridge.bridge-nf-call-iptables = 1</span></span>
<span id="cb14-4"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">net.ipv4.ip_forward = 1</span></span>
<span id="cb14-5"><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">EOF</span></span></code></pre></div></div>
<p>Apply the changes:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb15" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb15-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sudo</span> sysctl <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">--system</span></span></code></pre></div></div>
</section>
</section>
<section id="step-2-installing-containerd" class="level3">
<h3 class="anchored" data-anchor-id="step-2-installing-containerd">Step 2: Installing Containerd</h3>
<p>Install containerd and its dependencies:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb16" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb16-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sudo</span> apt install <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-y</span> curl gnupg2 software-properties-common apt-transport-https ca-certificates</span>
<span id="cb16-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sudo</span> curl <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-fsSL</span> https://download.docker.com/linux/ubuntu/gpg <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">|</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sudo</span> gpg <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">--dearmour</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-o</span> /etc/apt/trusted.gpg.d/docker.gpg</span>
<span id="cb16-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sudo</span> add-apt-repository <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"deb [arch=amd64] https://download.docker.com/linux/ubuntu </span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$(</span><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">lsb_release</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-cs</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">)</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;"> stable"</span></span>
<span id="cb16-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sudo</span> apt update</span>
<span id="cb16-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sudo</span> apt install <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-y</span> containerd.io</span></code></pre></div></div>
<p>Configure containerd:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb17" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb17-1"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">containerd</span> config default <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">|</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sudo</span> tee /etc/containerd/config.toml <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span>/dev/null <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;&amp;</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb17-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sudo</span> sed <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-i</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'s/SystemdCgroup \= false/SystemdCgroup \= true/g'</span> /etc/containerd/config.toml</span>
<span id="cb17-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sudo</span> systemctl restart containerd</span>
<span id="cb17-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sudo</span> systemctl enable containerd</span></code></pre></div></div>
</section>
<section id="step-3-installing-kubernetes-components" class="level3">
<h3 class="anchored" data-anchor-id="step-3-installing-kubernetes-components">Step 3: Installing Kubernetes Components</h3>
<p>Add the Kubernetes repository:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb18" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb18-1"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">curl</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-s</span> https://packages.cloud.google.com/apt/doc/apt-key.gpg <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">|</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sudo</span> apt-key add <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-</span></span></code></pre></div></div>
<p>Add the Kubernetes repository:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb19" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb19-1"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">echo</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.28/deb/ /"</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">|</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sudo</span> tee /etc/apt/sources.list.d/kubernetes.list</span></code></pre></div></div>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb20" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb20-1"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">curl</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-fsSL</span> https://pkgs.k8s.io/core:/stable:/v1.28/deb/Release.key <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">|</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sudo</span> gpg <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">--dearmor</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-o</span> /etc/apt/keyrings/kubernetes-apt-keyring.gpg</span></code></pre></div></div>
<p>Install Kubernetes components:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb21" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb21-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sudo</span> apt update</span>
<span id="cb21-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sudo</span> apt install <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-y</span> kubelet kubeadm kubectl</span>
<span id="cb21-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sudo</span> apt-mark hold kubelet kubeadm kubectl</span></code></pre></div></div>
</section>
<section id="step-4-initializing-the-cluster" class="level3">
<h3 class="anchored" data-anchor-id="step-4-initializing-the-cluster">Step 4: Initializing the Cluster</h3>
<p>On the master node only:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb22" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb22-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sudo</span> kubeadm init <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb22-2">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">--pod-network-cidr</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>10.10.0.0/16 <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb22-3">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">--control-plane-endpoint</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>k8s-master.quocanuit.local</span></code></pre></div></div>
<p>After initialization, set up kubectl:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb23" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb23-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mkdir</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-p</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$HOME</span>/.kube</span>
<span id="cb23-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sudo</span> cp <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-i</span> /etc/kubernetes/admin.conf <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$HOME</span>/.kube/config</span>
<span id="cb23-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sudo</span> chown <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">id</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-u</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">)</span>:<span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">id</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-g</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">)</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$HOME</span>/.kube/config</span></code></pre></div></div>
<p>Verify the cluster status:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb24" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb24-1"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">kubectl</span> cluster-info</span>
<span id="cb24-2"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">kubectl</span> get nodes</span></code></pre></div></div>
<section id="joining-worker-nodes" class="level4">
<h4 class="anchored" data-anchor-id="joining-worker-nodes">Joining Worker Nodes</h4>
<p>On worker nodes, use the join command output from the master’s initialization. If needed, regenerate the join command on the master:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb25" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb25-1"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">kubeadm</span> token create <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">--print-join-command</span></span></code></pre></div></div>
</section>
</section>
<section id="step-5-installing-calico-network-plugin" class="level3">
<h3 class="anchored" data-anchor-id="step-5-installing-calico-network-plugin">Step 5: Installing Calico Network Plugin</h3>
<p>On the master node, download and install Calico:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb26" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb26-1"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">curl</span> https://raw.githubusercontent.com/projectcalico/calico/v3.25.0/manifests/calico.yaml <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-O</span></span></code></pre></div></div>
<p>Modify the CIDR in the Calico config:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb27" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb27-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sudo</span> nano calico.yaml</span></code></pre></div></div>
<p>Update the <code>CALICO_IPV4POOL_CIDR</code> to match your pod network CIDR:</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://annq.io.vn/posts/install-k8s-cluster/9XeUpeF.png" class="img-fluid figure-img"></p>
<figcaption>calico</figcaption>
</figure>
</div>
<p>Apply the configuration:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb28" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb28-1"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">kubectl</span> apply <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-f</span> calico.yaml</span></code></pre></div></div>
<p>Verify the installation:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb29" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb29-1"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">kubectl</span> get pods <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-n</span> kube-system</span></code></pre></div></div>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://annq.io.vn/posts/install-k8s-cluster/f8GN612.png" class="img-fluid figure-img"></p>
<figcaption>calico status</figcaption>
</figure>
</div>
<p>Check node status:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb30" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb30-1"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">kubectl</span> get nodes</span></code></pre></div></div>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://annq.io.vn/posts/install-k8s-cluster/gjz0ZR5.png" class="img-fluid figure-img"></p>
<figcaption>ready</figcaption>
</figure>
</div>
</section>
<section id="step-6-optional-installing-kubernetes-dashboard" class="level3">
<h3 class="anchored" data-anchor-id="step-6-optional-installing-kubernetes-dashboard">Step 6 (Optional): Installing Kubernetes Dashboard</h3>
<p>For better cluster management, install the Kubernetes Dashboard:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb31" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb31-1"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">kubectl</span> apply <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-f</span> https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml</span></code></pre></div></div>
<p>Create a file named <code>kubernetes-dashboard-service-np.yaml</code>:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb32" style="background: #f1f3f5;"><pre class="sourceCode yaml code-with-copy"><code class="sourceCode yaml"><span id="cb32-1"><span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">---</span></span>
<span id="cb32-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">apiVersion</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> v1</span></span>
<span id="cb32-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kind</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> ServiceAccount</span></span>
<span id="cb32-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">metadata</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span></span>
<span id="cb32-5"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">  </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">name</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> admin-user</span></span>
<span id="cb32-6"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">  </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">namespace</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> kubernetes-dashboard</span></span>
<span id="cb32-7"><span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">---</span></span>
<span id="cb32-8"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">apiVersion</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> rbac.authorization.k8s.io/v1</span></span>
<span id="cb32-9"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kind</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> ClusterRoleBinding</span></span>
<span id="cb32-10"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">metadata</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span></span>
<span id="cb32-11"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">  </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">name</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> admin-user</span></span>
<span id="cb32-12"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">roleRef</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span></span>
<span id="cb32-13"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">  </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">apiGroup</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> rbac.authorization.k8s.io</span></span>
<span id="cb32-14"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">  </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kind</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> ClusterRole</span></span>
<span id="cb32-15"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">  </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">name</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> cluster-admin</span></span>
<span id="cb32-16"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">subjects</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span></span>
<span id="cb32-17"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">  </span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">-</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kind</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> ServiceAccount</span></span>
<span id="cb32-18"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">    </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">name</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> admin-user</span></span>
<span id="cb32-19"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">    </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">namespace</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> kubernetes-dashboard</span></span>
<span id="cb32-20"><span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">---</span></span>
<span id="cb32-21"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">kind</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> Service</span></span>
<span id="cb32-22"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">apiVersion</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> v1</span></span>
<span id="cb32-23"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">metadata</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span></span>
<span id="cb32-24"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">  </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">namespace</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> kubernetes-dashboard</span></span>
<span id="cb32-25"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">  </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">name</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> kubernetes-dashboard-service-np</span></span>
<span id="cb32-26"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">  </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">labels</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span></span>
<span id="cb32-27"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">    </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">k8s-app</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> kubernetes-dashboard</span></span>
<span id="cb32-28"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">spec</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span></span>
<span id="cb32-29"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">  </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">type</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> NodePort</span></span>
<span id="cb32-30"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">  </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ports</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span></span>
<span id="cb32-31"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">    </span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">-</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">port</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> </span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8443</span></span>
<span id="cb32-32"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">      </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nodePort</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> </span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30002</span></span>
<span id="cb32-33"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">      </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">targetPort</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> </span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8443</span></span>
<span id="cb32-34"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">      </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">protocol</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> TCP</span></span>
<span id="cb32-35"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">  </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">selector</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span></span>
<span id="cb32-36"><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">    </span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">k8s-app</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">:</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;"> kubernetes-dashboard</span></span></code></pre></div></div>
<p>Apply the configuration:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb33" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb33-1"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">kubectl</span> apply <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-f</span> kubernetes-dashboard-service-np.yaml</span></code></pre></div></div>
<p>Generate an authentication token:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb34" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb34-1"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">kubectl</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-n</span> kubernetes-dashboard create token admin-user</span></code></pre></div></div>
<p>Access the dashboard at <code>https://192.168.72.129:30002</code> and enter the token.</p>
<blockquote class="blockquote">
<p>If you can’t access the dashboard, verify your IP and port settings. You might need to set up SSH tunneling for secure access.</p>
</blockquote>
<p>After successful login, you’ll see the Kubernetes Dashboard:</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://annq.io.vn/posts/install-k8s-cluster/BZ3xIfJ.png" class="img-fluid figure-img"></p>
<figcaption>dashboard</figcaption>
</figure>
</div>
</section>
<section id="references" class="level3">
<h3 class="anchored" data-anchor-id="references">References</h3>
<ol type="1">
<li><a href="https://nvtienanh.info/blog/cai-dat-kubernetes-cluster-tren-ubuntu-server-22-04">Cai dat Kubernetes cluster tren Ubuntu server 22.04</a></li>
<li><a href="https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/">Installing kubeadm</a></li>
<li><a href="https://upcloud.com/resources/tutorials/deploy-kubernetes-dashboard">How to deploy Kubernetes Dashboard quickly and easily</a></li>
</ol>


</section>

 ]]></description>
  <category>EN</category>
  <category>Kubernetes</category>
  <guid>https://annq.io.vn/posts/install-k8s-cluster/</guid>
  <pubDate>Wed, 10 Apr 2024 00:00:00 GMT</pubDate>
  <media:content url="https://annq.io.vn/posts/install-k8s-cluster/4AlMMH1.png" medium="image" type="image/png" height="76" width="144"/>
</item>
</channel>
</rss>
