{"id":140,"date":"2022-10-19T17:55:58","date_gmt":"2022-10-19T17:55:58","guid":{"rendered":"https:\/\/merserver.com\/?p=140"},"modified":"2022-10-19T17:56:05","modified_gmt":"2022-10-19T17:56:05","slug":"how-to-install-kubernetes-on-ubuntu-22-04-jammy-jellyfish-linux","status":"publish","type":"post","link":"http:\/\/merserver.com\/index.php\/2022\/10\/19\/how-to-install-kubernetes-on-ubuntu-22-04-jammy-jellyfish-linux\/","title":{"rendered":"How to install Kubernetes on Ubuntu 22.04 Jammy Jellyfish Linux"},"content":{"rendered":"\n<p>Kubernetes is leading software in container orchestration. Kubernetes works by managing clusters, which is simply a set of hosts meant for running containerized applications. In order to have a Kubernetes cluster, you need a minimum of two nodes \u2013 a&nbsp;<strong>master node<\/strong>&nbsp;and a&nbsp;<strong>worker node<\/strong>. Of course, you can expand the cluster by adding as many worker nodes as you need.<br><br>In this tutorial, we\u2019re going to deploy a Kubernetes cluster consisting of two nodes, both of which are running&nbsp;<a href=\"https:\/\/linuxconfig.org\/ubuntu-22-04-features-and-release-date\" target=\"_blank\" rel=\"noreferrer noopener\">Ubuntu 22.04<\/a>&nbsp;Jammy Jellyfish. Having two nodes in our cluster is the most basic configuration possible, but you\u2019ll be able to scale that configuration and add more nodes if you wish.<\/p>\n\n\n\n<p><strong>In this tutorial you will learn:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>How to install Docker<\/li><li>How to install Kubernetes<\/li><li>How to configure a master and worker node<\/li><li>How to join a worker node to a Kubernetes cluster<\/li><li>How to deploy Nginx (or any containerized app) in a Kubernetes cluster<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image\" id=\"attachment_14623\"><img decoding=\"async\" src=\"https:\/\/merserver.com\/wp-content\/uploads\/2022\/10\/04-how-to-install-kubernetes-on-ubuntu-22-04-jammy-jellyfish-linux.png\" alt=\"Deploying Kubernetes on Ubuntu 22.04 Jammy Jellyfish Linux\" class=\"wp-image-14623\"\/><figcaption>Deploying Kubernetes on Ubuntu 22.04 Jammy Jellyfish Linux<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Category<\/th><th>Requirements, Conventions or Software Version Used<\/th><\/tr><\/thead><tbody><tr><td>System<\/td><td><a href=\"https:\/\/linuxconfig.org\/ubuntu-22-04-download\" target=\"_blank\" rel=\"noreferrer noopener\">Ubuntu 22.04 Jammy Jellyfish<\/a><\/td><\/tr><tr><td>Software<\/td><td>Kubernetes<\/td><\/tr><tr><td>Other<\/td><td>Privileged access to your Linux system as root or via the&nbsp;<code>sudo<\/code>&nbsp;command.<\/td><\/tr><tr><td>Conventions<\/td><td><strong>#<\/strong>&nbsp;\u2013 requires given&nbsp;<a href=\"https:\/\/linuxconfig.org\/linux-commands\" target=\"_blank\" rel=\"noreferrer noopener\">linux commands<\/a>&nbsp;to be executed with root privileges either directly as a root user or by use of&nbsp;<code>sudo<\/code>&nbsp;command<br><strong>$<\/strong>&nbsp;\u2013 requires given&nbsp;<a href=\"https:\/\/linuxconfig.org\/linux-commands\" target=\"_blank\" rel=\"noreferrer noopener\">linux commands<\/a>&nbsp;to be executed as a regular non-privileged user<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Scenario<\/h2>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>Before we dive in, let\u2019s estabish the particulars of our scenario. As mentioned above, our cluster is going to have two nodes, and both of those nodes are running&nbsp;<a href=\"https:\/\/linuxconfig.org\/ubuntu-22-04-download\" target=\"_blank\" rel=\"noreferrer noopener\">Ubuntu 22.04 Jammy Jellyfish<\/a>. One will be the&nbsp;<strong>master node<\/strong>&nbsp;and can be easily identified with its hostname of&nbsp;<code>kubernetes-master<\/code>. The second node will be our&nbsp;<strong>worker node<\/strong>&nbsp;and have a hostname of&nbsp;<code>kubernetes-worker<\/code>.<\/p>\n\n\n\n<p>The master node will deploy a Kubernetes cluster and the worker node simply joins it. Since Kubernetes clusters are designed to run containerized software, after we get our cluster up and running we are going to deploy a Nginx server container as a proof of concept.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Install Docker<\/h2>\n\n\n\n<p>Both of the nodes will need to have Docker installed on them, as Kubernetes relies on it.&nbsp;<a href=\"https:\/\/linuxconfig.org\/how-to-open-a-terminal-on-ubuntu-xenial-xerus-16-04-linux\" target=\"_blank\" rel=\"noreferrer noopener\">Open a command line terminal<\/a>&nbsp;and type the following commands on both the master and the worker node to install Docker:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo apt update\n$ sudo apt install docker.io\n<\/pre>\n\n\n\n<p>Once Docker has finished installing, use the following commmands to start the service and to make sure it starts automatically after each reboot:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo systemctl start docker\n$ sudo systemctl enable docker\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Install Kubernetes<\/h2>\n\n\n\n<p>Now we are ready to install Kubernetes. Just like all the other commands up to this point, make sure that you are doing this on both nodes. On your Kubernetes master and worker, first install the&nbsp;<code>apt-transport-https<\/code>&nbsp;package, which will allow us to use http and https in Ubuntu\u2019s repositories. Now is also a good time to install&nbsp;<code>curl<\/code>&nbsp;since we will need it in a moment:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo apt install apt-transport-https curl\n<\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>Next, add the Kubernetes signing key to both systems:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ curl -s https:\/\/packages.cloud.google.com\/apt\/doc\/apt-key.gpg | sudo apt-key add\n<\/pre>\n\n\n\n<p>Next, we\u2019ll add the Kubernetes package repository. Note that at the time of this writing, Ubuntu 16.04 Xenial Xerus is the latest Kubernetes repository available. This should eventually be superseded by Ubuntu 22.04 Jammy Jellyfish, and the following command can then be updated from&nbsp;<code>xenial<\/code>&nbsp;to&nbsp;<code>jammy<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo apt-add-repository \"deb http:\/\/apt.kubernetes.io\/ kubernetes-xenial main\"\n<\/pre>\n\n\n\n<p>Now we can install Kubernetes:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo apt install kubeadm kubelet kubectl kubernetes-cni\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Disable swap memory<\/h2>\n\n\n\n<p>Kubernetes will refuse to function if your system is using swap memory. Before proceeding further, make sure that the master and worker node have swap memory disabled with this command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo swapoff -a\n<\/pre>\n\n\n\n<p>That command will disable swap memory until your systems reboot, so to make this change persists, use nano or your favorite text editor to open this file:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo nano \/etc\/fstab\n<\/pre>\n\n\n\n<p>Inside this file, comment out the&nbsp;<code>\/swapfile<\/code>&nbsp;line by preceeding it with a&nbsp;<code>#<\/code>&nbsp;symbol, as seen below. Then, close this file and save the changes.<\/p>\n\n\n\n<figure class=\"wp-block-image\" id=\"attachment_14626\"><a href=\"https:\/\/merserver.com\/wp-content\/uploads\/2022\/10\/01-how-to-install-kubernetes-on-ubuntu-22-04-jammy-jellyfish-linux.png\"><img decoding=\"async\" src=\"https:\/\/merserver.com\/wp-content\/uploads\/2022\/10\/01-how-to-install-kubernetes-on-ubuntu-22-04-jammy-jellyfish-linux.png\" alt=\"Add # to comment out swapfile line\" class=\"wp-image-14626\"\/><\/a><figcaption>Add # to comment out swapfile line<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Set hostnames<\/h2>\n\n\n\n<p>Next, ensure that all of your nodes have a unique hostname. In our scenario, we\u2019re using the hostnames&nbsp;<code>kubernetes-master<\/code>&nbsp;and&nbsp;<code>kubernetes-worker<\/code>&nbsp;to easily differentiate our hosts and identify their roles. Use the following command if you need to change your hostnames:<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo hostnamectl set-hostname kubernetes-master\n<\/pre>\n\n\n\n<p>And on the worker node:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo hostnamectl set-hostname kubernetes-worker\n<\/pre>\n\n\n\n<p>You won\u2019t notice the hostname changes in the terminal until you open a new one. Lastly, make sure that all of your nodes have an accurate time and date, otherwise you will run into trouble with invalid TLS certificates.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Initialize Kubernetes master server<\/h2>\n\n\n\n<p>Now we\u2019re ready to initialize the Kubernetes master node. To do so, enter the following command on your master node:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">kubernetes-master:~$ sudo kubeadm init\n<\/pre>\n\n\n\n<figure class=\"wp-block-image\" id=\"attachment_14625\"><a href=\"https:\/\/merserver.com\/wp-content\/uploads\/2022\/10\/02-how-to-install-kubernetes-on-ubuntu-22-04-jammy-jellyfish-linux.png\"><img decoding=\"async\" src=\"https:\/\/merserver.com\/wp-content\/uploads\/2022\/10\/02-how-to-install-kubernetes-on-ubuntu-22-04-jammy-jellyfish-linux.png\" alt=\"Kubernetes on Ubuntu 22.04 master node is now initialized\" class=\"wp-image-14625\"\/><\/a><figcaption>Kubernetes on Ubuntu 22.04 master node is now initialized<\/figcaption><\/figure>\n\n\n\n<p>The Kubernetes master node has now been initialized. The output gives us a&nbsp;<code>kubeadm join<\/code>&nbsp;command that we will need to use later to join our worker node(s) to the master node. So, take note of this command for later.<\/p>\n\n\n\n<p>The output from above also advises us to run several commands as a regular user to start using the Kubernetes cluster. Run those three commands on the master node:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">kubernetes-master:~$ mkdir -p $HOME\/.kube\nkubernetes-master:~$ sudo cp -i \/etc\/kubernetes\/admin.conf $HOME\/.kube\/config\nkubernetes-master:~$ sudo chown $(id -u):$(id -g) $HOME\/.kube\/config\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Deploy a pod network<\/h2>\n\n\n\n<p>Next step is to deploy a pod network. The pod network is used for communication between hosts and is necessary for the Kubernetes cluster to function properly. For this we will use the Flannel pod network. Issue the following two commands on the master node:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">kubernetes-master:~$ kubectl apply -f https:\/\/raw.githubusercontent.com\/coreos\/flannel\/master\/Documentation\/kube-flannel.yml\nkubernetes-master:~$ kubectl apply -f https:\/\/raw.githubusercontent.com\/coreos\/flannel\/master\/Documentation\/k8s-manifests\/kube-flannel-rbac.yml\n<\/pre>\n\n\n\n<p>Depending on your environment, it may take just a few seconds or a minute to bring the entire flannel network up. You can use the&nbsp;<code>kubectl<\/code>&nbsp;command to confirm that everything is up and ready:<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<pre class=\"wp-block-preformatted\">kubernetes-master:~$ kubectl get pods --all-namespaces\n<\/pre>\n\n\n\n<figure class=\"wp-block-image\" id=\"attachment_14624\"><a href=\"https:\/\/merserver.com\/wp-content\/uploads\/2022\/10\/03-how-to-install-kubernetes-on-ubuntu-22-04-jammy-jellyfish-linux.png\"><img decoding=\"async\" src=\"https:\/\/merserver.com\/wp-content\/uploads\/2022\/10\/03-how-to-install-kubernetes-on-ubuntu-22-04-jammy-jellyfish-linux.png\" alt=\"Pod network is successfully deployed\" class=\"wp-image-14624\"\/><\/a><figcaption>Pod network is successfully deployed<\/figcaption><\/figure>\n\n\n\n<p>When all of the STATUS column shows \u2018Running,\u2019 it\u2019s an indication that everything is finished deploying and good to go.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Join the Kubernetes cluster<\/h2>\n\n\n\n<p>Now our cluster is ready to have the worker nodes join. Use the&nbsp;<code>kubeadm join<\/code>&nbsp;command retrieved earlier from the Kubernetes master node initialization output to join your Kubernetes cluster:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">kubernetes-worker:~$ sudo kubeadm join 192.168.1.220:6443 --token 1exb8s.2t4k3b5syfc3jfmo --discovery-token-ca-cert-hash sha256:72ad481cee4918cf2314738419356c9a402fb609263adad48c13797d0cba2341\n<\/pre>\n\n\n\n<figure class=\"wp-block-image\" id=\"attachment_14623\"><a href=\"https:\/\/merserver.com\/wp-content\/uploads\/2022\/10\/04-how-to-install-kubernetes-on-ubuntu-22-04-jammy-jellyfish-linux.png\"><img decoding=\"async\" src=\"https:\/\/merserver.com\/wp-content\/uploads\/2022\/10\/04-how-to-install-kubernetes-on-ubuntu-22-04-jammy-jellyfish-linux.png\" alt=\"Joining worker node to Kubernetes cluster\" class=\"wp-image-14623\"\/><\/a><figcaption>Joining worker node to Kubernetes cluster<\/figcaption><\/figure>\n\n\n\n<p>Back on your Kubernetes master node, confirm that&nbsp;<code>kubernetes-worker<\/code>&nbsp;is now part of our Kubernetes cluster with this command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">kubernetes-master:~$ kubectl get nodes\n<\/pre>\n\n\n\n<figure class=\"wp-block-image\" id=\"attachment_14622\"><a href=\"https:\/\/merserver.com\/wp-content\/uploads\/2022\/10\/05-how-to-install-kubernetes-on-ubuntu-22-04-jammy-jellyfish-linux.png\"><img decoding=\"async\" src=\"https:\/\/merserver.com\/wp-content\/uploads\/2022\/10\/05-how-to-install-kubernetes-on-ubuntu-22-04-jammy-jellyfish-linux.png\" alt=\"Displays what nodes are currently in the Kubernetes cluster\" class=\"wp-image-14622\"\/><\/a><figcaption>Displays what nodes are currently in the Kubernetes cluster<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Deploying a service on Kubernetes cluster<\/h2>\n\n\n\n<p>Now we are ready to deploy a service into the Kubernetes cluster. In our example, we will deploy a Nginx server into our new cluster as a proof of concept. Run the following two commands on your master node:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">kubernetes-master:~$ kubectl apply -f https:\/\/k8s.io\/examples\/controllers\/nginx-deployment.yaml\nkubernetes-master:~$ kubectl run --image=nginx nginx-server --port=80 --env=\"DOMAIN=cluster\"\nkubernetes-master:~$ kubectl expose deployment nginx-deployment --port=80 --name=nginx-http\n<\/pre>\n\n\n\n<p>You should now see a new nginx docker container deployed on your worker node:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">kubernetes-worker:~$ sudo docker ps\n<\/pre>\n\n\n\n<figure class=\"wp-block-image\" id=\"attachment_14621\"><a href=\"https:\/\/merserver.com\/wp-content\/uploads\/2022\/10\/06-how-to-install-kubernetes-on-ubuntu-22-04-jammy-jellyfish-linux.png\"><img decoding=\"async\" src=\"https:\/\/merserver.com\/wp-content\/uploads\/2022\/10\/06-how-to-install-kubernetes-on-ubuntu-22-04-jammy-jellyfish-linux.png\" alt=\"New docker Nginx container is up and running on Kubernetes worker node\" class=\"wp-image-14621\"\/><\/a><figcaption>New docker Nginx container is up and running on Kubernetes worker node<\/figcaption><\/figure>\n\n\n\n<p>You can see a running list of all available services running in your cluster with the following command, issued from the Kubernetes maser node:<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<pre class=\"wp-block-preformatted\">kubernetes-master:~$ kubectl get svc\n<\/pre>\n\n\n\n<figure class=\"wp-block-image\" id=\"attachment_14620\"><a href=\"https:\/\/merserver.com\/wp-content\/uploads\/2022\/10\/07-how-to-install-kubernetes-on-ubuntu-22-04-jammy-jellyfish-linux.png\"><img decoding=\"async\" src=\"https:\/\/merserver.com\/wp-content\/uploads\/2022\/10\/07-how-to-install-kubernetes-on-ubuntu-22-04-jammy-jellyfish-linux.png\" alt=\"Displays what containerized services are running on the Kubernetes cluster\" class=\"wp-image-14620\"\/><\/a><figcaption>Displays what containerized services are running on the Kubernetes cluster<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Closing Thoughts<\/h2>\n\n\n\n<p>In this tutorial, we learned how to setup Kubernetes to deploy containerized applications on Ubuntu 22.04 Jammy Jellyfish. We setup a basic cluster consisting of two hosts, a master and a worker, though this can be scaled to many more worker nodes if necessary.<\/p>\n\n\n\n<p>We saw how to configure Docker and other pre-requisites, as well as deploy an Nginx server in our new cluster as a proof of concept. Of course, this same configuration can be used to deploy any number of containerized applications.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Kubernetes is leading software in container orchestration. Kubernetes works by managing clusters, which is simply a set of hosts meant for running containerized applications. In order to have a Kubernetes cluster, you need a minimum of two nodes \u2013 a&nbsp;master node&nbsp;and a&nbsp;worker node. Of course, you can expand the cluster by adding as many worker&#8230;<\/p>\n<p class=\"more-link-wrap\"><a href=\"http:\/\/merserver.com\/index.php\/2022\/10\/19\/how-to-install-kubernetes-on-ubuntu-22-04-jammy-jellyfish-linux\/\" class=\"more-link\">Read More<span class=\"screen-reader-text\"> &ldquo;How to install Kubernetes on Ubuntu 22.04 Jammy Jellyfish Linux&rdquo;<\/span> &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,5],"tags":[],"class_list":["post-140","post","type-post","status-publish","format-standard","hentry","category-it","category-kubernetes"],"_links":{"self":[{"href":"http:\/\/merserver.com\/index.php\/wp-json\/wp\/v2\/posts\/140","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/merserver.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/merserver.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/merserver.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/merserver.com\/index.php\/wp-json\/wp\/v2\/comments?post=140"}],"version-history":[{"count":1,"href":"http:\/\/merserver.com\/index.php\/wp-json\/wp\/v2\/posts\/140\/revisions"}],"predecessor-version":[{"id":148,"href":"http:\/\/merserver.com\/index.php\/wp-json\/wp\/v2\/posts\/140\/revisions\/148"}],"wp:attachment":[{"href":"http:\/\/merserver.com\/index.php\/wp-json\/wp\/v2\/media?parent=140"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/merserver.com\/index.php\/wp-json\/wp\/v2\/categories?post=140"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/merserver.com\/index.php\/wp-json\/wp\/v2\/tags?post=140"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}