Author Photo

Being a Linux Enthusiast and a Fan of Open Source Software, I created Ahmer’s SysAdmin Recipes blog to share my experiences with other System Administrators. The curiosity doesn’t let me stop; therefore, I am constantly trying to learn new software tools and techniques. Whereas I also have the passion and the patience to teach the others.

I am always ready to accept new challenges and wish to explore the areas, that I haven’t worked on. Please give me your feedback and help me improve this blog.

Monday, 6 May 2019

Install Lightweight Kubernetes (K3s) Cluster with k3OS

Install & Configure Kubernetes (K8s) cluster with k3OSk3OS is a lightweight operating system, optimally designed to run Kubernetes (k8s) or more specifically Lightweight Kubernetes (k3s) clusters. The main aim of k3OS is to minimize operating system maintenance while running a Kubernetes (k3s) cluster. k3OS and k3s both are developed by Rancher Labs.

k3OS Kernel is forked from Ubuntu, while many of the user-space binaries comes from Alpine Linux, whereas some code is derived from LinuxKit. Additionally, the k3OS operating system is designed to be managed by kubectl once a cluster is bootstrapped. All aspects of the operating system of nodes will be managed by Kubernetes.

In this article, we will install a Lightweight Kubernetes (k3s) cluster with k3OS operating system.

A very good and comprehensive reading reference for k3OS is its documentation.  But you should also read Kubernetes in Action by Manning Publications, to have a good understanding of Kubernetes technology and its usage.

 

System Specification:

We have provisioned two virtual machines with following specifications:

Role: Server Agent
CPU: 3.4 Ghz (2 cores) 3.4 Ghz (2 cores)
Memory: 2 GB 2 GB
Storage: 60 GB 60 GB

 

Installing k3OS Operating System:

We have downloaded iso of k3OS operating system from GitHub.

Attach the downloaded file k3os-amd64.iso in our virtual machine and start VM.

k3os-boot-menu-01

Select Run k3OS LiveCD or Installation and press <ENTER>.

The system then boot-up and reach at the login prompt. Login as rancher user without password.

After successful login, you may acquire a Bash shell. Then, use following command to set a password for rancher user. It will enable us to login to this machine using a ssh client.

k3os-command-line-01

Connect with this machine using ssh as rancher user.

login as: rancher rancher@192.168.116.161's password: Welcome to k3OS! Refer to https://github.com/rancher/k3os for README and issues By default mode of k3OS is to run a single node cluster. Use "kubectl" to access it. The node token in /var/lib/rancher/k3s/server/node-token can be used to join agents to this server. You can configure this system or install to disk using "sudo os-config" k3os-24483 [~]$

Check the version of the k3OS operating system.

k3os-24483 [~]$ cat /etc/os-release NAME="k3OS" VERSION="k3OS v0.2.0-rc4" ID=k3os ID_LIKE=alpine PRETTY_NAME="k3OS v0.2.0-rc4" VERSION_ID="v0.2.0-rc4" HOME_URL="https://k3os.io/" SUPPORT_URL="https://k3os.io/" BUG_REPORT_URL="https://github.com/rancher/k3os/issues" ISO_URL="https://github.com/rancher/k3os/releases/download/v0.2.0-rc4/k3os.iso"

Check Kernel version.

k3os-29512 [~]$ uname -a Linux k3os-29512 4.15.0-47-generic #50 SMP Tue Apr 23 19:17:07 UTC 2019 x86_64 GNU/Linux

Repeat above steps on both machines.

 

Installing & Configuring Kubernetes Server Node with k3OS:

Start k3OS configurations using following command.

k3os-24483 [~]$ sudo os-config Running k3OS configuration Choose operation 1. Install to disk 2. Configure server or agent Select Number []: 1

Choose the required operation and press <ENTER>.

Choose installation partition table type 1. gpt 2. msdos Select Number [1]: 2

Choose installation partition table type according to your Hardware. If your system is UEFI based, then you must select gpt partition table type. If your system is BIOS based, then you must select msdos table partition type.

Press <ENTER>.

Config system with cloud-init file? [y/N]: N

k3OS operating system can be configured using a cloud-init file for automatic and fast provisioning of cloud instances. cloud-init is a separate topic and beyond the scope of this article, therefore, we are not using it now for the sake of simplicity. Once, you made your hand dirty with k3OS, then you can use cloud-init file.

Authorize GitHub users to SSH? [y/N]: N

If you are required to allow users to access GitHub using ssh from this machine then choose 'y' otherwise select 'N'. If you choose 'y' then you have to provide a comma seperated list of authorized GitHub users.

Please enter password for [rancher]:

Set a password for rancher user.

Please enter password for [rancher]: *** Confirm password for [rancher]: *** chpasswd: password for 'rancher' changed Run as server or agent? 1. server 2. agent Select Number [1]: 1

Choose the role of this node and press <ENTER>.

Token or cluster secret (optional): karachi

Provide a cluster secret and Press <ENTER>. We will need this cluster secret, when joining a new node to our Lightweight Kubernetes (k3s) cluster.

k3OS then install and configure itself on our machine.

1+0 records in 1+0 records out 1048576 bytes (1.0 MB, 1.0 MiB) copied, 0.0881194 s, 11.9 MB/s mke2fs 1.44.5 (15-Dec-2018) Creating filesystem with 488448 1k blocks and 122400 inodes Filesystem UUID: feae576f-b4de-402d-87b7-d99afa44e6bc Superblock backups stored on blocks: 8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409 Allocating group tables: done Writing inode tables: done Creating journal (8192 blocks): done Writing superblocks and filesystem accounting information: done mount: /run/k3os/iso: WARNING: device write-protected, mounted read-only. sending incremental file list ./ boot/ boot/initrd boot/vmlinuz k3os/ k3os/system/ k3os/system/k3s/ k3os/system/k3s/current -> v0.4.0 k3os/system/k3s/v0.4.0/ k3os/system/k3s/v0.4.0/k3s k3os/system/kernel/ k3os/system/kernel/4.15.0-47-generic/ k3os/system/kernel/4.15.0-47-generic/kernel.squashfs sbin/ sbin/init -> k3os sbin/k3os -> /k3os/system/k3os/current/k3os sbin/k3s -> /k3os/system/k3s/current/k3s sent 342,567,853 bytes received 151 bytes 32,625,524.19 bytes/sec total size is 342,483,652 speedup is 1.00 1+0 records in 1+0 records out 440 bytes copied, 0.001107 s, 397 kB/s * Rebooting system in 5 seconds

Check the current nodes in Kubernetes cluster.

k3os-24483 [~]$ kubectl get nodes NAME STATUS ROLES AGE VERSION k3os-24483 Ready <none> 3m44s v1.14.1-k3s.4

We have successfully installed k3OS and configured a Lightweight Kubernetes (k3s) Server node.

 

Installing & Configuring Kubernetes Agent Node with k3OS:

Start k3OS configurations using following commands.

k3os-13179 [~]$ sudo os-config Running k3OS configuration Choose operation 1. Install to disk 2. Configure server or agent Select Number []: 1

Choose an operation and press <ENTER>.

Choose installation partition table type 1. gpt 2. msdos Select Number [1]: 2

Choose installation partition table type and press <ENTER>.

Config system with cloud-init file? [y/N]: N

We are not using a cloud-init file, therefore, choose 'N' and press <ENTER>.

Authorize GitHub users to SSH? [y/N]: N

If you want users to access GiHub from this machine then press 'y' otherwise 'N'. Press <ENTER>.

Please enter password for [rancher]: *** Confirm password for [rancher]: *** chpasswd: password for 'rancher' changed

Set a password for rancher user.

Run as server or agent? 1. server 2. agent Select Number [1]: 2

We are configuring this machine as an Agent node, therefore, select option '2' and press <ENTER>.

URL of server: https://192.168.116.163:6443 Token or cluster secret: karachi

Provide URL of Lightweight Kubernetes (k3s) Server and the cluster secret.

k3OS is then install & configure itself on this machine.

1+0 records in 1+0 records out 1048576 bytes (1.0 MB, 1.0 MiB) copied, 0.0601958 s, 17.4 MB/s mke2fs 1.44.5 (15-Dec-2018) Creating filesystem with 488448 1k blocks and 122400 inodes Filesystem UUID: 22642d1d-c4e6-405f-86a9-864ad08da671 Superblock backups stored on blocks: 8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409 Allocating group tables: done Writing inode tables: done Creating journal (8192 blocks): done Writing superblocks and filesystem accounting information: done mount: /run/k3os/iso: WARNING: device write-protected, mounted read-only. sending incremental file list ./ boot/ boot/initrd boot/vmlinuz k3os/ k3os/system/ k3os/system/k3s/ k3os/system/k3s/current -> v0.4.0 k3os/system/k3s/v0.4.0/ k3os/system/k3s/v0.4.0/k3s k3os/system/kernel/ k3os/system/kernel/4.15.0-47-generic/ k3os/system/kernel/4.15.0-47-generic/kernel.squashfs sbin/ sbin/init -> k3os sbin/k3os -> /k3os/system/k3os/current/k3os sbin/k3s -> /k3os/system/k3s/current/k3s sent 342,567,853 bytes received 151 bytes 10,225,910.57 bytes/sec total size is 342,483,652 speedup is 1.00 1+0 records in 1+0 records out 440 bytes copied, 0.154485 s, 2.8 kB/s * Rebooting system in 5 seconds

Check nodes status.

k3os-24483 [~]$ kubectl get nodes NAME STATUS ROLES AGE VERSION k3os-14464 Ready <none> 35s v1.14.1-k3s.4 k3os-24483 Ready <none> 15m v1.14.1-k3s.4

Check cluster status.

k3os-24483 [~]$ kubectl cluster-info Kubernetes master is running at https://localhost:6443 CoreDNS is running at https://localhost:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

 

Testing our Lightweight Kubernetes (k3s) cluster:

To test our Kubernetes cluster, create a simple nginx web server.

k3os-24483 [~]$ kubectl run --generator=run-pod/v1 my-nginx --image=nginx --replicas=2 --port=80 pod/my-nginx created

Export nginx service.

k3os-24483 [~]$ kubectl expose deployment my-nginx --port=80 --type=LoadBalancer service/my-nginx exposed

Check Kubernetes (K3s) services.

k3os-24483 [~]$ kubectl get services --watch NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.43.0.1 <none> 443/TCP 36m my-nginx LoadBalancer 10.43.231.232 192.168.116.164 80:30692/TCP 101s

Browse URL http://192.168.116.164 in a client's browser.

nginx

We have successfully installed & configured a Lightweight Kubernetes (K3s) cluster with k3OS operating system.

Install Lightweight Kubernetes (K3s) Cluster with k3OS


YOU MIGHT ALSO LIKE:

No comments:

Post a Comment