Install Servers
I have used Ubuntu Server 18.04 LTS.
Install one Master-Node and 3 Worker-Nodes.
! Don’t clone the Ubuntu-VMs. I had troubles with networking when I have used cloned VMs. Even though the Mac-Addresses of the interfaces were different there were troubles with networking in Kubernetes.
! Each node needs to have internet access! Because they will pull the docker images….
! You may setup your Master-Node also as Docker-Registry, so that the Nodes can pull images (self made images) from the Master.
Setup Network
We use 10.0.15.x as cluster network on a host-only vm network. In that case we set two IPs. The 192.168.163.x is the vm network, so that the VMs are accesible from your host (where the VMs are hosted on). The 10.0.15.x is the internal cluster network. Additionally we have a second interface with DHCP enabled, this interface should get a network in your public network with internet connection.
vi /etc/netplan/50-cloud-init.yaml
network:
ethernets:
ens33:
dhcp4: true
optional: true
ens38:
dhcp4: false
addresses: [10.0.15.10/24, 192.168.163.10/24]
> netplan apply
> vi /etc/hosts
10.0.15.10 master
10.0.15.21 worker01
10.0.15.22 worker02
10.0.15.23 worker02
> hostnamectl set-hostname master
> reboot
Install Docker
> apt install docker.io -y
Systemd must be used for cgroupdriver in docker
> cat > /etc/docker/daemon.json <<EOF
{
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2",
"insecure-registries" : ["master:5000"]
}
EOF
> mkdir -p /etc/systemd/system/docker.service.d
> systemctl daemon-reload
> systemctl restart docker
Install Docker Registry on Master
> docker run -d -p 5000:5000 --restart=always --name registry registry:2
add your Registry server as insecure registry to /etc/docker/daemon.json, if you haven’t it done in one of the previous steps.
{
"insecure-registries" : ["master:5000"]
}
push an image to your Registry server:
> docker tag <image> master:5000/<image> # tag your image
> docker push master:5000/<image> # push your image
Install Kubernetes
Disable Swap
> swapon -s
> swapoff -a
> vim /etc/fstab # comment out line with swap device
> reboot
> apt install -y apt-transport-https
> curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
> echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" > /etc/apt/sources.list.d/> kubernetes.list
> apt update
> apt install -y kubeadm kubelet kubectl
Master Node Cluster Initalization
> kubeadm config images pull
> kubeadm init --pod-network-cidr=10.244.10.0/16 --apiserver-advertise-address=10.0.15.10
Your Kubernetes control-plane has initialized successfully!
To start using your cluster, you need to run the following as a regular user:
> mkdir -p $HOME/.kube
> sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
> sudo chown $(id -u):$(id -g) $HOME/.kube/config
You should now deploy a pod network to the cluster (use a regular user)
> kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
or
> kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d 'n')"
Check the state
> kubectl get nodes
> kubectl get pods --all-namespaces
Join Worker Node(s)
Then you can join any number of worker nodes by running the following on each as root at the worker nodes (copy this from the outpout kubeadm init)
> kubeadm join 10.0.15.10:6443 --token w8vr52.wtful961u754ev8b
--discovery-token-ca-cert-hash sha256:b07d512632b0117bfe81716b57d0c00b64cabd8222c5ffae04f447291a7c16f8
check if the nodes have been joined:
> kubectl get nodes