We are now going to configure the cluster. For the sake of traceability, this configuration wonโt be done via CLI flags, but via
a configuration file. The path of the cluster config file will later be referenced as the , and should be inside /etc/kubernetes.
Following
flannel requirements, you need to use --pod-network-cidr with address 10.244.0.0./16. This CLI option is equivalent to networking.podSubnet in our file (see
this issue).
The variable must be set to the network address of your master node through the VPN. You can get it like so:
apiVersion:kubeadm.k8s.io/v1beta2kind:InitConfigurationlocalAPIEndpoint:advertiseAddress:---apiVersion:kubeadm.k8s.io/v1beta2kind:ClusterConfigurationclusterName:networking:podSubnet:"10.244.0.0/16"apiServer:extraArgs:audit-policy-file:/etc/kubernetes/audit-log-policy.yamlaudit-log-path:/extraVolumes:- name:audit-policyhostPath:/etc/kubernetes/audit-log-policy.yamlmountPath:/etc/kubernetes/audit-log-policy.yaml# See apiServer.extraArgs.audit-policy-filereadOnly:true- name:audit-loghostPath:mountPath:pathType:DirectoryOrCreatereadOnly:false
Now, the kubelet has been configured. Well, mainly. Because, as mentioned
here, it assumes that it should work through the default gateway (our public network), but thatโs not what we want. So, we need to explicitly declare our nodeโs IP.
1
2
3
4
sed -i.bak "s/KUBELET_EXTRA_ARGS=/KUBELET_EXTRA_ARGS=--node-ip=$(ip -4 a show tun0 | grep -Po 'inet \K[0-9.]*') /" /etc/sysconfig/kubelet
systemctl restart kubelet.service
# Verify that the `--node-ip` flag is appended to the `/usr/bin/kubelet` processsystemctl status kubelet.service
To communicate with each other, pods need a network layer. Weโll use flannel for this. Following its
installation instruction, you need to deploy
this file. But thereโs a problem: as mentioned in the
configuration documentation, flannel use the default route (our public network) by default, and we still want to use the VPN fio this. So, Iโve just added a single line in the
kube-flannel file to specify our VPN interface (line 188, - --iface=tun0).
# If you want to run pods on the master (not recommended), run the following command:kubectl taint nodes $(hostname) node-role.kubernetes.io/master-
# To undo, run the followingkubectl taint nodes $(hostname) node-role.kubernetes.io/master:NoSchedule
Join workers
At the end of the kubeadm init... command, a join command was issued if everything went OK. Execute this command on every workers you want in your cluster. The command is something like below:
If lost, you can create a new one by executing following command on the control pane with:
1
kubeadm token create --print-join-command
1
2
3
4
sed -i.bak "s/KUBELET_EXTRA_ARGS=/KUBELET_EXTRA_ARGS=--node-ip=$(ip -4 a show tun0 | grep -Po 'inet \K[0-9.]*') /" /etc/sysconfig/kubelet
systemctl restart kubelet.service
# Verify that the --node-ip flag is appended to the /usr/bin/kubelet processsystemctl status kubelet.service
You can check nodes by running following command from the control pane
1
2
3
kubectl get nodes
# Or watchkubectl get nodes -w
After some time, you should see the new node joining the cluster !
You may repeat this part of the process during the life of your cluster to add new nodes.
To check if everything works so far, start a test nginx instance:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
kubectl create namespace nginx-test
kubectl --namespace nginx-test run nginx --image nginx
# This may take some time to fetch the containerkubectl --namespace nginx-test expose pod nginx --port 80 --type LoadBalancer
nginx_ip="$(kubectl --namespace nginx-test get svc nginx --output json | jq --raw-output '.status.loadBalancer.ingress[].ip')"if[[ ! -z "$nginx_ip"]];thenecho -e "$(tput setaf 2)Has public IP $nginx_ip. Testing connection. If nothing appears bellow, you might have a firewall configuration issue.$(tput sgr0)"if ! timeout 5 curl http://$nginx_ip;thenecho -e "$(tput setaf 1)nginx unreachable. You might have a firewall configuration issue.$(tput sgr0)"fielseecho"No public IP"fiunset nginx_ip
This should return Has public IP with an IP that should be reachable from the host & the HTML of the default nginx page. If not, then you might have additional configuration to do.
Cleanup the namespace afterwards
1
kubectl delete namespace nginx-test
Hey, weโve done important things here ! Maybe itโs time to commitโฆ
1
2
3
4
git add .
git commit -m "Kickstart the cluster
Following guide @ https://gerkindev.github.io/devblog/walkthroughs/kubernetes/02-cluster/"
Troubleshoot
Kubelet is not running
I had to reinstall kubelet to clear previous runs configurations.