Create create-vm.sh:
#!/bin/sh dist='bionic' if [ -z "$1" ] ; then echo Specify a virtual-machine name. exit 1 fi sudo virt-install \ --name $1 \ --ram 4096 \ --disk path=/mnt/A/images/$1.img,size=30 \ --vcpus 2 \ --os-type linux \ --os-variant ubuntu18.04 \ --network bridge:br0,model=virtio \ --location "http://gb.archive.ubuntu.com/ubuntu/dists/${dist}/main/installer-amd64/" \ --graphics vnc,listen=192.168.2.13 \ --noautoconsole \ --extra-args "ip=192.168.2.30::192.168.2.1:255.255.255.0:${1}.internal.stroila.net:eth0:none"
Run create-vm.sh
./create-vm.sh k8s-master
Get the vnc display
virsh vncdisplay k8s-master
Turn off swap (edit /etc/fstab) and comment out the line that says swap.
and...
swapoff -a
Set static ip
$ cat /etc/netplan/01-netcfg.yaml # This file describes the network interfaces available on your system # For more information, see netplan(5). network: version: 2 renderer: networkd ethernets: ens3: dhcp4: no dhcp6: no addresses: [192.168.2.30/24, '2001:1::1/64'] gateway4: 192.168.2.1 nameservers: addresses: [192.168.2.1]
Configure the nodes
#!/bin/sh sudo apt update \ && sudo apt install -qy docker.io systemctl enable docker.service sudo apt install gnupg2 -y sudo apt update \ && sudo apt install -y apt-transport-https \ && curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" \ | sudo tee -a /etc/apt/sources.list.d/kubernetes.list \ && sudo apt update sudo apt update \ && sudo apt-get install -y \ kubelet \ kubeadm \ kubernetes-cni
Clone the vm
virt-clone --original k8s-master --name k8s-w1 --auto-clone virt-clone --original k8s-master --name k8s-w2 --auto-clone virt-clone --original k8s-master --name k8s-w3 --auto-clone ...
Set the static ip and hostname on the clones
hostnamectl set-hostname k8s-w1.internal.stroila.net ...
Create the cluster. On the master node:
sudo kubeadm init
Copy of the Kube config:
mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config
Install networking
kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"
To alter the private subnet that Weavenet uses for allocating IP addresses to Pods (containers):
curl -SL "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')&env.IPALLOC_RANGE=172.16.8.64/27" \ | kubectl apply -f -
To join the workers run on each worker:
kubeadm join 192.168.2.30:6443 --token jwm5ss.drp2ohpl53anl8r2 \ --discovery-token-ca-cert-hash sha256:39196d23b782299298b374ef8ec9637a2a1a29be286d98b820c34a30d073d2a3
Now you can list the nodes:
$ kubectl get nodes NAME STATUS ROLES AGE VERSION k8s-master.internal.stroila.net Ready master 21m v1.15.2 k8s-w1.internal.stroila.net Ready <none> 4m v1.15.2 k8s-w2.internal.stroila.net Ready <none> 2m26s v1.15.2 k8s-w3.internal.stroila.net Ready <none> 95s v1.15.2
https://kubernetes.io/docs/tasks/access-application-cluster/web-ui-dashboard/