This guide will cover how to set-up the production kubernetes cluster for hosting our public website, api and front-end.
AB: Make cluster HA
Start by building two nodes, following the default node set-up procedure, and the install them into the infrastructure.
Once both nodes have booted-up, confirm that you can SSH into the nodes from the console.
[Console] ssh node@10.0.0.XXX
[Console] ssh node@10.0.0.YYY
Clone this repo on the Console and make a copy of the example
directory located at ./ansible/inventory/example
[Console] cp -R ansible/inventory/example ansible/inventory/prod-cluster
Edit the hosts.ini
located in ./ansible/inventory/prod-cluster
so node-1 IP address is the master list and node-2 is in the node list
[Console] nano ansible/inventory/prod-cluster/hosts.ini
[master]
10.0.0.XXX
[node]
10.0.0.YYY
[k3s_cluster:children]
master
node
Run the Ansible playbook to install K3s across all of the nodes in our cluster.
[Console] ansible-playbook ansible/site.yml -i ansible/inventory/prod-cluster/hosts.ini
If the playbook completes successfully you should see output like this
PLAY RECAP ****************************************************************************************************
10.0.0.XXX : ok=21 changed=12 unreachable=0 failed=0 skipped=10 rescued=0 ignored=0
10.0.0.YYY : ok=10 changed=5 unreachable=0 failed=0 skipped=10 rescued=0 ignored=0
Copy the kubernetes config file from the master node to the Console.
[Console] scp node@10.0.0.XXX:~/.kube/config ~/.kube/config
Test that all of the nodes are up and running by running this command.
[Console] kubectl --kubeconfig=.kube/config get nodes
You should get a response that looks like this.
NAME STATUS ROLES AGE VERSION
node-1 Ready control-plane,master 3m6s v1.26.9+k3s1
node-2 Ready <none> 2m37s v1.26.9+k3s1
Lets test that everything is working by deploying a container that will just return hello-world
when we make a GET request to the root.
k3s/echo.yml will make a deployment, service and an ingress.
[Console] kubectl --kubeconfig=.kube/config apply -f k3s/echo.yml
deployment.apps/echo-deployment created
service/echo-service created
ingress.networking.k8s.io/echo-ingress created
[Console] kubectl --kubeconfig=.kube/config get pods
Add your master production nodes IP to /etc/hosts
on your work computer and go to http://echo.local
sudo nano /etc/hosts
10.0.0.XXX echo.local
AB: k8s dashboard
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.1.1/cert-manager.yaml
kubectl get pods --namespace cert-manager
NAME READY STATUS RESTARTS AGE cert-manager-5c6866597-zw7kh 1/1 Running 0 2m cert-manager-cainjector-577f6d9fd7-tr77l 1/1 Running 0 2m cert-manager-webhook-787858fcdb-nlzsq 1/1 Running 0