When deploying Kubernetes with the vsphere provider is possible to configure the hosts by passing commands that are executed before kubeadm runs by configuring preKubeadmCommands in the KubeadmConfigTemplate and KubeadmControlPlane objects:
KubeadmConfigTemplate.spec.template.spec.preKubeadmCommands
KubeadmControlPlane.spec.kubeadmConfigSpec.preKubeadmCommands
To do so, please generate a cluster.yaml by using the flag --dry-run and locate the two appearances of the preKubeadmCommands under the objects KubeadmConfigTemplate and KubeadmControlPlane.
In the example below, the preKubeadmCommands section includes commands to change sshd service configuration, restart sshd service, define default route in the host, force chrony syncronization and restart chronyd service:
preKubeadmCommands:
- hostname "{{ ds.meta_data.hostname }}"
- echo "::1 ipv6-localhost ipv6-loopback" >/etc/hosts
- echo "127.0.0.1 localhost" >>/etc/hosts
- echo "127.0.0.1 {{ ds.meta_data.hostname }}" >>/etc/hosts
- echo "10.129.4.35 harbor.sadielo.network" >> /etc/hosts
- echo "54.39.171.125 vcenter.ca1.ksphere-platform.d2iq.cloud" >> /etc/hosts
- sudo sed -i "/^[^#]*PasswordAuthentication[[:space:]]no/c\PasswordAuthentication yes" /etc/ssh/sshd_config
- sudo service sshd restart
- ip route add default via <IP Addr> dev eth0
- chronyc -a makestep
- systemctl restart chronyd
- echo "{{ ds.meta_data.hostname }}" >/etc/hostname
- systemctl daemon-reload
- /run/konvoy/restart-containerd-and-wait.sh
- /run/kubeadm/konvoy-set-kube-proxy-configuration.sh
After modifying the preKubeadmCommands in the cluster.yaml, proceed to create the cluster with:
kubectl create -f cluster.yaml