Summary
In this Lab we will learn about step by step process for adding Windows Server and Linux Server as Node in existing k8s Cluster
Prerequisites
1. A compatible Linux host (Linux distributions based on Ubuntu, Debian and Red Hat) or Windows Server host (Windows Server 2016/2019)
2. 2 GB or more of RAM per machine (any less will leave little room for your apps).
3. 2 CPUs or more.
4. Network connectivity between other Nodes and Master in the cluster (Static or DHCP).
5. Unique hostname, MAC address, and product_uuid for every node. See here for more details.
6. Certain ports are open on your machines for Master-Node and Node-Node communication
Adding Windows Server Node
Preparation
1. Enable Nested Virtualization and MAC-Spoofing for Windows Node:
Set-VMProcessor -VMName "<name>" -ExposeVirtualizationExtensions $true
Get-VMNetworkAdapter -VMName "<name>" | Set-VMNetworkAdapter -MacAddressSpoofing On
2. Install Container feature from Server Manage
Install Container Feature from Add and Remover (Server Manager)
3. Install Docker
[Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls"
Install-Module Dockermsftprovider -Force
install-package docker -ProviderName DockerMsftProvider -Force
Name Version Source Summary
—- ——- —— ——-
Docker 19.03.5 DockerDefault Contains Docker EE for use with Windows Server.
Start Docker Service
net start docker
4. Crete C:\k folder for storing Kubernetes Binaries, Cluster Configuration and Kubernetes Components (Kubelet, Kubectl, kubeadm and kube-proxy)
mkdir C:\k
5. Set Environment variable for kubectl
$env:Path += ";C:\k"
[Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:\k", [EnvironmentVariableTarget]::Machine)
$env:KUBECONFIG="C:\k\config"
[Environment]::SetEnvironmentVariable("KUBECONFIG", "C:\k\config", [EnvironmentVariableTarget]::User)
6. Check kubctl configuration:
kubectl config view
7. Download the Flannel start.ps1 script
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
wget https://raw.githubusercontent.com/Microsoft/SDN/master/Kubernetes/flannel/start.ps1 -o c:\k\start.ps1
wget https://raw.githubusercontent.com/microsoft/SDN/master/Kubernetes/flannel/start-kubelet.ps1 -o c:\k\start-kubelet.ps1
wget https://raw.githubusercontent.com/microsoft/SDN/master/Kubernetes/flannel/start-kubeproxy.ps1 -o start-kubeproxy.ps1
wget https://raw.githubusercontent.com/microsoft/SDN/master/Kubernetes/flannel/stop.ps1 -o c:\k\stop.ps1
8. Copy config file $HOME/.kube/config from master into c:\k directory on Windows worker.
9. Once you are done, the c:\k directory should look as follows:
10. Run following command to ‘Join Node’ to the Kubernetes Cluster
.\start.ps1 -ManagementIP 192.168.1.21 -NetworkMode overlay -ClusterCIDR 10.244.0.0/16 -ServiceCIDR 10.96.0.0/12 -KubeDnsServiceIP 10.96.0.10 -LogDir C:\k -interface Ethernet
11. Verify Nodes status:
kubectl get nodes -o wide
Adding Linux Node of K8s Cluster
Preparation
1. Disable Swap
sudo swapoff -a
Nano /etc/fstab
Comment out “#” /swapfile
2. Disable Linux SE (Security Enhanced Linux)
Setenforce 0
Sed -I 's/enforcing/disabled/g' /etc/selinux/config
Grep disabled /etc/selinux/config | grep -v '#'
3.. Configure Linux Node’s iptables to correctly see bridged traffic, ensure net.bridge.bridge-nf-call-iptables is set to 1 in sysctl config
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sudo sysctl --system
1. Add Google’s apt repository gpg key
sudo apt-get update && sudo apt-get install -y apt-transport-https curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
Add the Kubernetes apt repository
cat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF
Update the package list
sudo apt-get update
2. Install following packages Docker, kubelet, kubeadm and kubectl
sudo apt-get install -y docker.io kubelet kubeadm kubectl kubernetes-cni
3. Check the status of our kubelet and our container runtime, docker
sudo systemctl status kubelet.service
sudo systemctl status docker.service
Ensure both are set to start when the system starts up
sudo systemctl enable kubelet.service
sudo systemctl enable docker.service
Note: We no longer wants ‘apt’ to maintain the upgrade of these packages rather depends on Kubernetes to maintain its own updates
sudo apt-mark hold kubelet kubeadm kubectl
Note: Kublet Config files: /var/lib/kubelet/config.yaml
4. Reload the systemd config and docker
sudo systemctl daemon-reload
sudo systemctl restart docker
5. Copy $Home/.kube/config from Master to Linux Server
mkdir -p $HOME/.kube
Use WinSCP to copy files from $Home/.kube/ from Master to $HOME/.kube on Linux Sever
sudo chown $(id -u):$(id -g) $HOME/.kube/config
6. Join Linux Node to Cluster
kubeadm join 10.0.0.4:6443 --token v0x6ow.ip4qaoea9krrhqsx
--discovery-token-ca-cert-hash sha256:5512a6b4f8702b814528a3fc832bfad84d56d7369332b6e7ef192dde4ed41775
7. Check the status of Kubernetes Cluster Nodes
kubectl get nodes -o wide