<?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: Gnanaprakash Ramswami</title>
    <description>The latest articles on DEV Community by Gnanaprakash Ramswami (@prakashvra).</description>
    <link>https://dev.to/prakashvra</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%2F822047%2F7a76f621-d1c1-4ce6-8735-b2d1dba6d322.png</url>
      <title>DEV Community: Gnanaprakash Ramswami</title>
      <link>https://dev.to/prakashvra</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/prakashvra"/>
    <language>en</language>
    <item>
      <title>Part-1 How to setup a Kubernetes Cluster on AWS EC2 using Kubeadm, containerd and calico</title>
      <dc:creator>Gnanaprakash Ramswami</dc:creator>
      <pubDate>Sat, 12 Mar 2022 17:42:21 +0000</pubDate>
      <link>https://dev.to/prakashvra/how-to-setup-a-kubernetes-cluster-on-aws-ec2-using-kubeadm-containerd-and-calico-560o</link>
      <guid>https://dev.to/prakashvra/how-to-setup-a-kubernetes-cluster-on-aws-ec2-using-kubeadm-containerd-and-calico-560o</guid>
      <description>&lt;p&gt;In this article we will see how to setup a k8s cluster on AWS EC2 hosts using kubeadm.&lt;/p&gt;

&lt;p&gt;We will see in a series of steps &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Where to start?&lt;/li&gt;
&lt;li&gt;What applications to install?&lt;/li&gt;
&lt;li&gt;How do we install these applications?&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Where and what applications?
&lt;/h2&gt;

&lt;p&gt;Let us consider a basic cluster setup with 1 master node and 2 worker nodes.&lt;/p&gt;

&lt;p&gt;The master node runs the Control Plane and the worker nodes run the actual workloads&lt;/p&gt;

&lt;p&gt;Install these 2 apps on both master and worker nodes&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Container runtime&lt;/li&gt;
&lt;li&gt;Kubelet&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These 2 apps run as regular linux processes. They can be installed from the package repository like any other linux packages&lt;/p&gt;

&lt;p&gt;They need to be installed on all the nodes.&lt;/p&gt;

&lt;h3&gt;
  
  
  Master Node
&lt;/h3&gt;

&lt;p&gt;The master node runs the Control Plane along with the other necessary apps&lt;/p&gt;

&lt;p&gt;Control plane consists of the following apps which run as Pods.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;API server&lt;/li&gt;
&lt;li&gt;Controller Manager&lt;/li&gt;
&lt;li&gt;Scheduler &lt;/li&gt;
&lt;li&gt;Etcd&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Along with the above we need to install Kubeproxy which also runs as a Pod.&lt;/p&gt;

&lt;h3&gt;
  
  
  Worker Node
&lt;/h3&gt;

&lt;p&gt;Each of the worker nodes also should run Kubeproxy.&lt;/p&gt;

&lt;p&gt;Now, what are the main things required to deploy these Pods. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Kubernetes manifest files for each of the apps&lt;/li&gt;
&lt;li&gt;Security setup to prevent unauthorized access to the apps and securing the communication between the apps&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;How do we setup the apps in the master node? Because we said all the control plane apps run as Pods. Without the control plane in place how are we going to deploy and run these Pods? &lt;/p&gt;

&lt;p&gt;To solve this problem, we have something called Static Pods.&lt;/p&gt;

&lt;h3&gt;
  
  
  Static Pods
&lt;/h3&gt;

&lt;p&gt;These are pods managed directly by the kubelet daemon. So, the request for deploying a pod does not go through the API server in the control plane which is the case for any regular pod.&lt;/p&gt;

&lt;p&gt;How does kubelet daemon do this?&lt;/p&gt;

&lt;p&gt;Kubelet looks for any manifests available in a specific location on the Node where it is running.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;/etc/kubernetes/manifests&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
If the kubelet finds a Pod manifest in that location, it schedules a Pod directly on the node without having to go through the API server on the control plane running on the master node.&lt;/p&gt;

&lt;p&gt;Kubelet also restarts the static pods in case if the pods crash.&lt;/p&gt;
&lt;h3&gt;
  
  
  Creating static Pod manifests
&lt;/h3&gt;

&lt;p&gt;All static pod manifests have to be created and dropped into this location &lt;code&gt;/etc/kubernetes/manifests&lt;/code&gt; on their respective nodes.&lt;/p&gt;
&lt;h3&gt;
  
  
  Securing the pods
&lt;/h3&gt;

&lt;p&gt;Securing the communication between the apps within the cluster is one of the key aspects.&lt;/p&gt;

&lt;p&gt;K8s uses TLS certificate based security for this purpose.&lt;/p&gt;

&lt;p&gt;In order to decide which certificate will be used in each case we need to understand the communication flow between various components.&lt;/p&gt;

&lt;p&gt;First, most of all the components talk to the API server as it is the centre of all the communications. So, every other app that wants to talk to API server needs to send a TLS certificate. &lt;/p&gt;

&lt;p&gt;For learning purposes we can generate self-signed CA certificates for all the different apps. &lt;/p&gt;

&lt;p&gt;As API server is the one which receives requests, we need to setup server certificate. For all other apps which connect to API server, client certificates are to be setup.&lt;/p&gt;

&lt;p&gt;In cases where the API server connects to other apps, client certificate is required for API server too.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Server and client certificate for API server&lt;/li&gt;
&lt;li&gt;Client certificate for Controller manager and Scheduler&lt;/li&gt;
&lt;li&gt;Server and client certificate for Kubelet&lt;/li&gt;
&lt;li&gt;Server certificate for Etcd&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The certificates have to be stored on the respective nodes in this location /&lt;code&gt;etc/kubernetes/pki&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We also need to setup a certificate for the K8s admin users who will access the K8s cluster through API or CLI. This will be a client certificate.&lt;/p&gt;

&lt;p&gt;We need to generate a self-signed certificate which will be the root. Then generate certs for all the apps and sign them with the root.&lt;/p&gt;

&lt;p&gt;So, in order to get the k8s cluster up and running, we need to setup all these stuff.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;All mandatory process for master and worker nodes&lt;/li&gt;
&lt;li&gt;Manifest files for all pods&lt;/li&gt;
&lt;li&gt;Certificates for securing the apps&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We know by experience that these can take a lot of time if we do it manually. Luckily there is a CLI tool called Kubeadm. &lt;/p&gt;
&lt;h3&gt;
  
  
  Kubeadm
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://kubernetes.io/docs/reference/setup-tools/kubeadm/"&gt;Kubeadm&lt;/a&gt; is a tool created and maintained by Kubernetes. A very detailed documentation is available for this tool.&lt;/p&gt;

&lt;p&gt;This CLI tool helps in bootstrapping the k8s cluster by creating the necessary artifacts and performing the necessary actions.&lt;/p&gt;
&lt;h3&gt;
  
  
  Prerequisites
&lt;/h3&gt;

&lt;p&gt;For this session, we are going to setup our k8s cluster on AWS infrastructure. It is fine if you have a preference to use your own hardware/VM or any other cloud hosted infra.&lt;/p&gt;

&lt;p&gt;You can refer to kubeadm document &lt;a href="https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/#before-you-begin"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The following are the infrastructure requirements&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Any Linux based hosts. We will be using the latest Ubuntu VM available on AWS EC2.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Capacity of the servers - 2 CPUs and 2 GB or greater. We will choose t2.medium type as it provides 2 vCPU and 4 GiB memory.We will be creating 1 master node and 2 worker nodes and all 3 nodes will use the t2.medium type instances.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;All instances should be part of the same network. In this case all the EC2 instances will be part of a single VPC.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Should have unique host name and MAC address. All EC2 instances will have unique hostnames.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Required ports have to be opened. Please use the details &lt;a href="https://kubernetes.io/docs/reference/ports-and-protocols/"&gt;here &lt;/a&gt;to configure open the required ports.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Memory swapping should be disabled. Kubelets are designed to run the pods within the memory available on the host. Keeping swap enabled may destabilise the k8s cluster.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now the we understand the pre-requisites, we can start the installation!&lt;/p&gt;
&lt;h2&gt;
  
  
  How do we install?
&lt;/h2&gt;
&lt;h3&gt;
  
  
  &lt;em&gt;Step-1&lt;/em&gt; : Setup the hosts
&lt;/h3&gt;

&lt;p&gt;We need 3 hosts for creating the k8s cluster. We will be using AWS EC2 instances. You can sign up for &lt;a href="https://aws.amazon.com/free/"&gt;AWS Free tier&lt;/a&gt;. Please read through the free tier details. Once you have setup the k8s cluster and finished practicing, be sure to delete the EC2 instances so that you don't incur any unexpected cost.&lt;/p&gt;
&lt;h4&gt;
  
  
  Creating hosts
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Sign up for a new &lt;a href="https://aws.amazon.com/free/"&gt;AWS Free tier&lt;/a&gt; account if you don't have one.&lt;/li&gt;
&lt;li&gt;Create 3 t2.medium EC2 instances&lt;/li&gt;
&lt;li&gt;Name 1 instance as master and the other 2 instances as worker1 and worker2.&lt;/li&gt;
&lt;li&gt;Launch the instances. Don't forget to download the key-pair pem file as you will need this to ssh into the instances . Refer AWS documentation &lt;a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/launching-instance.html#step-7-review-instance-launch"&gt;here&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Note:- You can use the same keypair to access all the instances.&lt;/p&gt;

&lt;p&gt;Once you launch a Public IP will be assigned to each of those instances. Make sure you are able to SSH to the instances using the public IP. Use the following command from your laptop terminal to login.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssh -i k8s-cluster.pem ubuntu@54.179.167.247

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

&lt;/div&gt;



&lt;h4&gt;
  
  
  Setting up pre-requisites
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Disable memory swapping&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;SSH to each of the instances and execute this command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo swapoff -a
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Open required ports&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;By default AWS opens only port 22 for incoming SSH connections. So in order for all the k8s components running on 3 instances to communicate to each other, other ports need to be opened as per this &lt;a href="https://kubernetes.io/docs/reference/ports-and-protocols/"&gt;kubeadm reference&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Use the AWS security groups to configure the inbound ports. Refer to &lt;a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/working-with-security-groups.html"&gt;AWS EC2 Security Groups&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So far, we have provisioned the infrastructure and configured the necessary pre-requisites.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;em&gt;Step-2&lt;/em&gt; : Setup container runtime
&lt;/h3&gt;

&lt;p&gt;Container runtime has to be installed on master node and all the worker nodes.&lt;/p&gt;

&lt;p&gt;We will be using &lt;a href="https://containerd.io/"&gt;containerd&lt;/a&gt; as the container runtime as this is the standard recognised and used by all the managed k8s cluster providers &lt;a href="https://docs.aws.amazon.com/eks/index.html"&gt;EKS&lt;/a&gt;, &lt;a href="https://azure.microsoft.com/en-in/services/kubernetes-service/"&gt;AKS&lt;/a&gt; and &lt;a href="https://cloud.google.com/kubernetes-engine"&gt;GKE&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Please refer to &lt;a href="https://kubernetes.io/docs/concepts/architecture/cri/"&gt;Container Runtime Interface(CRI)&lt;/a&gt; if you want to refresh the concepts around the CRI.&lt;/p&gt;

&lt;p&gt;Ok. Let us install the container runtime.&lt;/p&gt;

&lt;p&gt;We will be following the steps given &lt;a href="https://kubernetes.io/docs/setup/production-environment/container-runtimes/#containerd"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The container installation steps are captured in a script file that can be found &lt;a href="https://github.com/prakashvra/kubernetes-setup/blob/3c47dd70ecc5d301a14034cfcbcbdf8c2a43da69/cri-install.sh"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Run the install script on all the nodes.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;em&gt;Step-3&lt;/em&gt; : Install kubeadm, kubelet and kubectl
&lt;/h3&gt;

&lt;p&gt;Now we need to install kubeadm, kubelet and kubectl on all the nodes. &lt;/p&gt;

&lt;p&gt;As mentioned earlier kubeadm will be used to initialise the cluster. It will create the necessary components for the control plane.&lt;/p&gt;

&lt;p&gt;Kubelet is required for starting pods and containers&lt;/p&gt;

&lt;p&gt;Kubectl is required for communicating with the cluster&lt;/p&gt;

&lt;p&gt;We will be following the steps given &lt;a href="https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/#installing-kubeadm-kubelet-and-kubectl"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The installation steps are captured in a script file that can be found &lt;a href="https://github.com/prakashvra/kubernetes-setup/blob/0487602e14857bfed3c35bf5bcdde4e505be941f/kubeadm-install.sh"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Run the above script on all the nodes.&lt;/p&gt;

&lt;p&gt;After completing the installations, check the status of each of the components by executing these commands&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;kubeadm version&lt;/li&gt;
&lt;li&gt;kubectl version&lt;/li&gt;
&lt;li&gt;service kubelet status&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;em&gt;Step-3&lt;/em&gt; : Initialise the cluster
&lt;/h3&gt;

&lt;p&gt;We will be using the kubeadm command to initialise the cluster. &lt;/p&gt;

&lt;p&gt;On the master node, execute the following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo kubeadm init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once the initialisation completes successfully, you should see some output like 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;Your Kubernetes control-plane has initialized successfully!

To start using your cluster, you need to run the following as a regular user:

  mkdir -p $HOME/.kube
  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  sudo chown $(id -u):$(id -g) $HOME/.kube/config

Alternatively, if you are the root user, you can run:

  export KUBECONFIG=/etc/kubernetes/admin.conf

You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
  https://kubernetes.io/docs/concepts/cluster-administration/addons/

Then you can join any number of worker nodes by running the following on each as root:

kubeadm join 172.31.17.66:6443 --token i1yboi.66y4mulp2gtblrvv \
    --discovery-token-ca-cert-hash sha256:4ddfa86a2cf2df7aaf21858c685e98ee2d9687252e2a2ef46df0c96223671504
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the output you will notice the different steps that were executed to setup the control plane and other processes.&lt;/p&gt;

&lt;p&gt;First executes &lt;code&gt;preflight&lt;/code&gt; step to check and pull the necessary images.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[preflight] Running pre-flight checks
[preflight] Pulling images required for setting up a Kubernetes cluster
[preflight] This might take a minute or two, depending on the speed of your internet connection
[preflight] You can also perform this action in beforehand using 'kubeadm config images pull'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Creates the certificates for all the k8s components.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[certs] Using certificateDir folder "/etc/kubernetes/pki"
[certs] Generating "ca" certificate and key
[certs] Generating "apiserver" certificate and key
[certs] apiserver serving cert is signed for DNS names [kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local master] and IPs [10.96.0.1 172.31.17.66]
[certs] Generating "apiserver-kubelet-client" certificate and key
[certs] Generating "front-proxy-ca" certificate and key
[certs] Generating "front-proxy-client" certificate and key
[certs] Generating "etcd/ca" certificate and key
[certs] Generating "etcd/server" certificate and key
[certs] etcd/server serving cert is signed for DNS names [localhost master] and IPs [172.31.17.66 127.0.0.1 ::1]
[certs] Generating "etcd/peer" certificate and key
[certs] etcd/peer serving cert is signed for DNS names [localhost master] and IPs [172.31.17.66 127.0.0.1 ::1]
[certs] Generating "etcd/healthcheck-client" certificate and key
[certs] Generating "apiserver-etcd-client" certificate and key
[certs] Generating "sa" key and public key
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Creates the necessary kube config files that connect to the API server.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[kubeconfig] Using kubeconfig folder "/etc/kubernetes"
[kubeconfig] Writing "admin.conf" kubeconfig file
[kubeconfig] Writing "kubelet.conf" kubeconfig file
[kubeconfig] Writing "controller-manager.conf" kubeconfig file
[kubeconfig] Writing "scheduler.conf" kubeconfig file
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Configures the kubelet config and starts the kubelet service&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Starting the kubelet
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Generates the manifest files for static pods and starts the pods.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[control-plane] Using manifest folder "/etc/kubernetes/manifests"
[control-plane] Creating static Pod manifest for "kube-apiserver"
[control-plane] Creating static Pod manifest for "kube-controller-manager"
[control-plane] Creating static Pod manifest for "kube-scheduler"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Sets up the manifest for etcd&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[etcd] Creating static Pod manifest for local etcd in "/etc/kubernetes/manifests"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Creates a ConfigMap called kubeadm-config in the kube-system namespace. This configuration is later used during &lt;code&gt;kubeadm join&lt;/code&gt;, &lt;code&gt;kubeadm-reset&lt;/code&gt; and &lt;code&gt;kubeadm-upgrade&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[upload-config] Storing the configuration used in ConfigMap "kubeadm-config" in the "kube-system" Namespace
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A kubelet config is created in kube-system namespace for all the kubelets in the cluster&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[kubelet] Creating a ConfigMap "kubelet-config-1.23" in namespace kube-system with the configuration for the kubelets in the cluster
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Adds a taint to prevent any workload pods from being scheduled on the master node.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[mark-control-plane] Marking the node master as control-plane by adding the taints [node-role.kubernetes.io/master:NoSchedule]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, creates bootstrap tokens to be used along with RBAC roles to enable authentication in the API server and used when a new cluster is created or joining new nodes to the cluster.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[bootstrap-token] Configuring bootstrap tokens, cluster-info ConfigMap, RBAC Roles
[bootstrap-token] configured RBAC rules to allow Node Bootstrap tokens to get nodes
[bootstrap-token] configured RBAC rules to allow Node Bootstrap tokens to post CSRs in order for nodes to get long term certificate credentials
[bootstrap-token] configured RBAC rules to allow the csrapprover controller automatically approve CSRs from a Node Bootstrap Token
[bootstrap-token] configured RBAC rules to allow certificate rotation for all node client certificates in the cluster
[bootstrap-token] Creating the "cluster-info" ConfigMap in the "kube-public" namespace
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Sets up CoreDNS as the DNS server and kube-proxy which is a network proxy that contains network rules on nodes and allows the traffic to the pods from inside and outside of cluster.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[addons] Applied essential addon: CoreDNS
[addons] Applied essential addon: kube-proxy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With this, we have completed the cluster initialisation step!!!&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;em&gt;Step-4&lt;/em&gt; : Connecting to the cluster
&lt;/h3&gt;

&lt;p&gt;We know that kubectl is the CLI tool to talk to the cluster. So, how does kubectl know to connect to the cluster.&lt;/p&gt;

&lt;p&gt;Let us do a quick check. Execute this command on the master node.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ubuntu@master:~$ kubectl get nodes
The connection to the server localhost:8080 was refused - did you specify the right host or port?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;kubectl is unable to connect as the kubeconfig is not setup yet.&lt;/p&gt;

&lt;p&gt;To make it work, we need to copy the kubeconfig to a default location on the node from where kubectl can use it.&lt;/p&gt;

&lt;p&gt;Execute the following commands.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  mkdir -p $HOME/.kube
  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  sudo chown $(id -u):$(id -g) $HOME/.kube/config
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, if you check the nodes, you should see an output like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ubuntu@master:~$ kubectl get nodes
NAME     STATUS     ROLES                  AGE   VERSION
master   NotReady   control-plane,master   11h   v1.23.4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The status of the master node is showing as 'NotReady' because the pod networking is not setup. So let us setup the pod network in the next step.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;em&gt;Step-5&lt;/em&gt; : Setup pod network
&lt;/h3&gt;

&lt;p&gt;You can refer to &lt;a href="https://kubernetes.io/docs/concepts/cluster-administration/networking/#how-to-implement-the-kubernetes-networking-model"&gt;k8s networking&lt;/a&gt; to understand the fundamental concepts.&lt;/p&gt;

&lt;p&gt;There are a number of networking solutions available. For this session we are going to use &lt;a href="https://projectcalico.docs.tigera.io/about/about-calico"&gt;calico&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Let us follow these steps to install calico on k8s. This installation has to be done on the master node.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;em&gt;Pre-requisites&lt;/em&gt;
&lt;/h4&gt;

&lt;p&gt;Check the calico &lt;a href="https://projectcalico.docs.tigera.io/getting-started/kubernetes/requirements#network-requirements"&gt;network requirements&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;In this session, we are using the default BGP bidirectional networking. For all the nodes, configure the inbound rules in security groups to allow TCP port 179. Only allow the VPC IP range for eg &lt;code&gt;172.31.0.0/16&lt;/code&gt;. &lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;em&gt;Installation&lt;/em&gt;
&lt;/h4&gt;

&lt;p&gt;Download the calico manifest file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl https://projectcalico.docs.tigera.io/manifests/calico.yaml -O

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

&lt;/div&gt;



&lt;p&gt;By default calico is configured to use 192.168.0.0/16 for the pod network. This should not overlap with the node IP range. If you are using this IP range already, make the necessary changes to the calico manifest.&lt;/p&gt;

&lt;p&gt;Uncomment these 2 lines in calico.yaml file if you want to use the default CIDR range.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;- name: CALICO_IPV4POOL_CIDR&lt;br&gt;
  value: "192.168.0.0/16"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now, apply the manifest.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl apply -f calico.yaml

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

&lt;/div&gt;



&lt;p&gt;After the installation completes, you can verify by checking the mode status and the calico pods created and running.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl get nodes
NAME     STATUS   ROLES                  AGE   VERSION
master   Ready    control-plane,master   3d    v1.23.4

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

&lt;/div&gt;



&lt;p&gt;Checking the pods.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl get pod -n kube-system
calico-kube-controllers-566dc76669-dcnbq   1/1     Running   0          56s
calico-node-nkhj9                          1/1     Running   0          56s
coredns-64897985d-28rdb                    1/1     Running   0          3d
coredns-64897985d-82m9d                    1/1     Running   0          3d
etcd-master                                1/1     Running   0          3d
kube-apiserver-master                      1/1     Running   0          3d
kube-controller-manager-master             1/1     Running   0          3d
kube-proxy-d25qg                           1/1     Running   0          3d
kube-scheduler-master                      1/1     Running   0          3d
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice the calico pods running and coredns pods in running state.&lt;/p&gt;

&lt;p&gt;We have successfully created a pod network for a single node cluster. We still need to bring the worker nodes into the pod network. To do this we need to join the worker nodes to the cluster.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;em&gt;Step-6&lt;/em&gt; : Add worker nodes to cluster
&lt;/h3&gt;

&lt;p&gt;Use the &lt;code&gt;kubadm join&lt;/code&gt; command shown in the result of Step-3 to join the worker nodes to cluster.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubeadm join 172.31.17.66:6443 --token l87fxe.30820pct4o7k80ax --discovery-token-ca-cert-hash sha256:4ddfa86a2cf2df7aaf21858c685e98ee2d9687252e2a2ef46df0c96223671504 

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

&lt;/div&gt;



&lt;p&gt;After execution of the command, you can verify if the nodes are joined in the cluster by executing the following in master node.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ubuntu@master:~$ kubectl get nodes
NAME      STATUS     ROLES                  AGE     VERSION
master    Ready      control-plane,master   3d1h    v1.23.4
worker1   Ready      &amp;lt;none&amp;gt;                 3m53s   v1.23.4
worker2   NotReady   &amp;lt;none&amp;gt;                 18s     v1.23.4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;em&gt;Step-7&lt;/em&gt; : Checking calico networking is setup for all nodes
&lt;/h3&gt;

&lt;p&gt;You can see 3 calico-node pods are running.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ubuntu@master:~$ kubectl get pod -A  -o wide
NAMESPACE         NAME                                       READY   STATUS    RESTARTS   AGE    IP               NODE      NOMINATED NODE   READINESS GATES
kube-system       calico-kube-controllers-566dc76669-fss4z   1/1     Running   0          30s    172.16.189.65    worker2   &amp;lt;none&amp;gt;           &amp;lt;none&amp;gt;
kube-system       calico-node-b7mwj                          1/1     Running   0          31s    172.31.28.225    worker2   &amp;lt;none&amp;gt;           &amp;lt;none&amp;gt;
kube-system       calico-node-ln7g2                          1/1     Running   0          31s    172.31.17.66     master    &amp;lt;none&amp;gt;           &amp;lt;none&amp;gt;
kube-system       calico-node-qkg8c                          1/1     Running   0          31s    172.31.22.174    worker1   &amp;lt;none&amp;gt;           &amp;lt;none&amp;gt;
kube-system       coredns-64897985d-28rdb                    1/1     Running   0          4d9h   192.168.219.65   master    &amp;lt;none&amp;gt;           &amp;lt;none&amp;gt;
kube-system       coredns-64897985d-82m9d                    1/1     Running   0          4d9h   192.168.219.66   master    &amp;lt;none&amp;gt;           &amp;lt;none&amp;gt;
kube-system       etcd-master                                1/1     Running   0          4d9h   172.31.17.66     master    &amp;lt;none&amp;gt;           &amp;lt;none&amp;gt;
kube-system       kube-apiserver-master                      1/1     Running   0          4d9h   172.31.17.66     master    &amp;lt;none&amp;gt;           &amp;lt;none&amp;gt;
kube-system       kube-controller-manager-master             1/1     Running   0          4d9h   172.31.17.66     master    &amp;lt;none&amp;gt;           &amp;lt;none&amp;gt;
kube-system       kube-proxy-d25qg                           1/1     Running   0          4d9h   172.31.17.66     master    &amp;lt;none&amp;gt;           &amp;lt;none&amp;gt;
kube-system       kube-proxy-nqwkm                           1/1     Running   0          32h    172.31.28.225    worker2   &amp;lt;none&amp;gt;           &amp;lt;none&amp;gt;
kube-system       kube-proxy-nvn4d                           1/1     Running   0          32h    172.31.22.174    worker1   &amp;lt;none&amp;gt;           &amp;lt;none&amp;gt;
kube-system       kube-scheduler-master                      1/1     Running   0          4d9h   172.31.17.66     master    &amp;lt;none&amp;gt;           &amp;lt;none&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let us create a nginx pod to check if the IP allocation works as expected.&lt;/p&gt;

&lt;p&gt;Create a nginx Pod manfiest.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apiVersion: v1
kind: Pod
metadata:
   name: nginx
   namespace: default
spec:
   containers:
   - name: nginx
     image: nginx
     ports:
       - containerPort: 80
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create the nginx pod&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl create -f nginx.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;View the pod details&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl get pods -o wide
NAME    READY   STATUS    RESTARTS   AGE   IP               NODE      NOMINATED NODE   READINESS GATES
nginx   1/1     Running   0          13s   192.168.189.65   worker2   &amp;lt;none&amp;gt;           &amp;lt;none&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can see the newly created nginx pod is assigned an IP from the CIDR block 192.168.0.0/16&lt;/p&gt;

&lt;p&gt;Let us create another pod using another simpler method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl run nginx2 --image=nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;View the pod details now&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl get pods -o wide
NAME     READY   STATUS    RESTARTS   AGE   IP                NODE      NOMINATED NODE   READINESS GATES
nginx    1/1     Running   0          57m   192.168.189.65    worker2   &amp;lt;none&amp;gt;           &amp;lt;none&amp;gt;
nginx2   1/1     Running   0          7s    192.168.235.130   worker1   &amp;lt;none&amp;gt;           &amp;lt;none&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can see the new pod 'nginx2' is scheduled on worker1 and the IP is within the CIDR range 192.168.0.0/16&lt;/p&gt;

&lt;p&gt;With this we have completed a basic k8s cluster setup and tested it.&lt;/p&gt;

&lt;p&gt;In the next article we will deploy a sample "go lang" application.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
