|
| 1 | +--- |
| 2 | +title: Working with Rancher and Kubernetes |
| 3 | +author: Antoine Le Morvan |
| 4 | +contributors: Steven Spencer, Ganna Zhyrnova |
| 5 | +update: 22-Feb-2024 |
| 6 | +tested_with: 9.3 |
| 7 | +tags: |
| 8 | + - rancher |
| 9 | + - kubernetes |
| 10 | + - containers |
| 11 | + - docker |
| 12 | +--- |
| 13 | + |
| 14 | +# Working with Rancher and Kubernetes |
| 15 | + |
| 16 | +**Kubernetes** (**K8s**) is an open-source container orchestration system for managing the deployment and management of containerized applications. |
| 17 | + |
| 18 | +K8S has made a name for itself on the market, so there's really no need to introduce it anymore. |
| 19 | + |
| 20 | +Cloud providers have made it easy to deploy managed Kubernetes platforms, but what about setting up and managing an on-premises cluster? |
| 21 | + |
| 22 | +How easy is it to manage multiple clusters, whether on-premise or multi-cloud? |
| 23 | + |
| 24 | +The last two questions can be answered in the negative... No, setting up an on-premise cluster isn't easy, and managing a multi-cloud cluster can be a real headache. |
| 25 | + |
| 26 | +That's where the subject of this guide comes in: **Rancher**! Rancher is also an open-source system, enabling the installation and orchestration of several multi-cloud or on-premise clusters, and providing interesting features such as an application catalog and a practical web interface for visualizing resources. |
| 27 | + |
| 28 | +Rancher will enable you to deploy kubernetes clusters managed by cloud providers, import existing kubernetes clusters or deploy K3S (for short, it's a lighter version of K8S) or K8S clusters. |
| 29 | + |
| 30 | +This guide will help you discover Rancher, install and start it, and then create an on-premise kubernetes cluster deployed on RockyLinux servers. |
| 31 | + |
| 32 | +## Rancher deployment |
| 33 | + |
| 34 | +Installing Rancher is quite trivial, as long as you have docker installed on your server. |
| 35 | + |
| 36 | +Docker installation is covered by the gemstone [docker installation](./gemstones/docker/). |
| 37 | + |
| 38 | +To run on a Rocky 9, rancher will also require modules to be loaded. |
| 39 | + |
| 40 | +One way of ensuring that the necessary modules are loaded during system startup is to create a `/etc/modules-load.d/rancher.conf` file with the following contents: |
| 41 | + |
| 42 | +```text |
| 43 | +ip_tables |
| 44 | +ip_conntrack |
| 45 | +iptable_filter |
| 46 | +ipt_state |
| 47 | +``` |
| 48 | + |
| 49 | +And the easiest way to apply that changes is to reboot the server: `sudo reboot`. |
| 50 | + |
| 51 | +Once rebooted, you can ensure the modules are loaded thanks to the `lsmod | grep <module_name>` command. |
| 52 | + |
| 53 | +We now have a system ready to receive the rancher container: |
| 54 | + |
| 55 | +```bash |
| 56 | +docker pull rancher/rancher:latest |
| 57 | +docker run -d --name=rancher --privileged --restart=unless-stopped -p 80:80 -p 443:443 rancher/rancher:latest |
| 58 | +``` |
| 59 | + |
| 60 | +!!! NOTE |
| 61 | + |
| 62 | + If you're curious, have a look at the new container's logs. You'll see that a K3S cluster (with a single node) has just been created! This is how rancher works in its standalone version. |
| 63 | + |
| 64 | +  |
| 65 | + |
| 66 | +As Rancher listens on port 443, open your firewall to allow access from the outside: |
| 67 | + |
| 68 | +```bash |
| 69 | +firewall-cmd --permanent --zone=public --add-service=https |
| 70 | +firewall-cmd --zone=public --add-service=https |
| 71 | +``` |
| 72 | + |
| 73 | +If you go to the newly deployed rancher web interface, a message will inform you how to retrieve the admin administrator password which is present in your container logs. |
| 74 | + |
| 75 | +To do this, launch the following command: |
| 76 | + |
| 77 | +```bash |
| 78 | +docker logs rancher 2>&1 | grep "Bootstrap Password:" |
| 79 | +``` |
| 80 | + |
| 81 | +You are ready to connect to the Rancher's webUI. |
| 82 | + |
| 83 | + |
| 84 | + |
| 85 | +!!! NOTE |
| 86 | + |
| 87 | + This solution is by no means production-ready. You'll need to make sure the system is highly available, but it's a good start. Consider deploying Rancher on an existing K8S cluster for optimal HA. |
| 88 | + |
| 89 | +## Kubernetes on RockyLinux 9 servers |
| 90 | + |
| 91 | +Rancher offers its own docker-based version of Kubernetes: RKE (Rancher Kubernetes Engine). |
| 92 | + |
| 93 | +All you need is several RockyLinux servers and the [Docker engine](./gemstones/docker/) installed on them. |
| 94 | + |
| 95 | +Don't forget that one of the requirements of kubernetes is to have an odd number of master nodes (1 or 3, for example). For the purposes of our tests, I propose to start with 3 master nodes and 2 additional nodes with only the worker role. |
| 96 | + |
| 97 | +Once Docker is installed on the servers, stop firewalld and run nftables on each servers: |
| 98 | + |
| 99 | +```bash |
| 100 | +systemctl stop firewalld |
| 101 | +systemctl disable firewalld |
| 102 | +systemctl start nftables |
| 103 | +systemctl enable nftables |
| 104 | +``` |
| 105 | + |
| 106 | +We are ready for our cluster creation. |
| 107 | + |
| 108 | +### Cluster creation |
| 109 | + |
| 110 | +In the cluster management area, create a new cluster: |
| 111 | + |
| 112 | + |
| 113 | + |
| 114 | +You are free to create a cluster in a hosted Kubernetes provider, provision new nodes and create a cluster using RKE2/K3s, or, and that is our case, use existing nodes and create a cluster using RKE2/K3s. |
| 115 | + |
| 116 | +Choose the last option. |
| 117 | + |
| 118 | +Enter a cluster name and description. |
| 119 | + |
| 120 | +Take your time to discover the various options available before launching cluster creation. |
| 121 | + |
| 122 | + |
| 123 | + |
| 124 | +Once the cluster has been created, go to the Registration tab to add our servers: |
| 125 | + |
| 126 | + |
| 127 | + |
| 128 | +First, select the various roles of the node you are adding and copy the necessary command line. If your cluster uses a self-signed certificate, check the appropriate box. |
| 129 | + |
| 130 | +Go to the node you wish to add to the configuration and paste the command you copied earlier. |
| 131 | + |
| 132 | +After a few minutes, the server will be added to the cluster, and if it's the first server and has all the roles, the cluster will become available in the web interface. |
| 133 | + |
| 134 | +Once you've added the 5 servers, you should get a result similar to this one: |
| 135 | + |
| 136 | + |
| 137 | + |
| 138 | +## Conclusion |
| 139 | + |
| 140 | +Congratulations! You've installed your first kubernetes cluster in just a few minutes/hours, thanks to Rancher's features. |
| 141 | + |
| 142 | +If you're new to kubernetes, you can already be proud of yourself: you're on the right track. You now have everything you need to continue your discovery of kubernetes. |
0 commit comments