K3S |
Oracle Cloud has a very generous forever free tier. I have been using k3s on my Raspberry Pi 4 machines for sometime in my local home network and it is working amazingly well.
I was very keen to deploy k3s for free on a cloud provider as a backup to my local clusters and finally managed to do that recently.
How to deploy k3s on Oracle Cloud ?
Kubernetes k3s cluster on Oracle Forever free tier |
We are going to use the forever free tier. As of December 2021, Oracle is giving us below options:
- ARM based machines with 24 GB RAM and 4 CPUs cores in total - I have decided to utilize this as 2 separate machines with each having 12 GB RAM, 2 CPUs and 15 GB default volume storage. One machine will be main node for k3s and other will be a worker node
- Two AMD machines with 1 Core and 1 GB RAM - I have used one machine as a k3s worker and the other as as MySQL database for high availability for k3s cluster
The installation of k3s is pretty straightforward. It is important to remember that we have taken one node as master and rest as slaves.
Machine Setup
On Master node (we will call it k3s-master)
Ampere ARM instance with 2 Octacore CPU and 12 GB RAM |
1. Visit Oracle Cloud create instance and create a VM (virtual machine) with Ubuntu as image and the CPU configuration as ARM and hard disk around 15 GB. This will be k3s-master
2. Now remember and download both the ssh keys as we need them for other machines:
SSH key menu in Oracle Cloud |
3. Once the machine is green (shows active in the instances section of Oracle Cloud), use the ssh key to login via the public ip address:
ssh -i
ssh -i id.rsa ubuntu@<PUBLIC IP ADDRESS>
Please change the IP address as per your machine. You might need to install Putty if you are using a Windows machine. Change the hostname by entering on the terminal:
hostnamectl set-hostname k3s-master
hostnamectl
On Slave nodes (we will call it k3s-mysql, k3s-amd-node1 and k3s-arm-node2)
1. Create another instance with AMD as CPU type, 10 GB HDD and 1 GB of RAM. This should be within free limits. This will be k3s-mysql (use hostnamectl command as before). Remember to specify the public ssh key you downloaded before in the ssh key section. We need to install mysql on this machine which can be done as per this article - install MySQL on ubuntu. Make sure you create a new user and a database. Give admin rights to this user to that database only in MySQL You need to note the private IP of this machine.
2. Create another instance with AMPERE ARM as CPU type, 2 OCTACORE CPU, 10 GB HDD and 12 GB of
RAM. This should be within free limits. This will be k3s-arm-node2 (use hostnamectl command as before). Remember to specify the public ssh key you downloaded before in the ssh key section. Note the private IP address of all machines so that we can use them and also change their hostnames
Installing k3s
1. Login to every machine and make sure you enter the following command:
sudo iptables -F
This commands flushes the iptables rules.
2. Now in k3s-master (use ssh to log in), we will install k3s server in high availability mode using the below command:
curl -sfL https://get.k3s.io | sh -s - server \
--token=SECRET \
--datastore-endpoint="mysql://username:password@tcp(hostname:3306)/database-name"
(Please replace the username, password, hostname - private IP of k3s-mysql and database-name as per your configuration)
3. Note the token string (K3S_TOKEN) which you get on k3s-master by using following command:
cat /var/lib/rancher/k3s/server/token
This will be used by worker nodes to join the k3s servers
4. Now log in to each worker node and enter following command:
K3S_TOKEN=SECRET k3s agent --server https://fixed-registration-address:6443
fixed-registration-address ---> k3s-master private IP address
SECRET ---> K3S_TOKEN from step 3.
That's it. Enjoy your free k3s (Kubernetes) cluster on Oracle Cloud.
0 comments:
Post a Comment
What do you think?.