- Introduction to Kubernetes
 
Prerequisites:
- Clean debian install
 - add-user meetup
 - Swap off 'sudo swapoff -a'
 
sudo apt install -y ca-certificates software-properties-common curl apt-transport-https
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/debian \
$(lsb_release -cs) \
stable"
sudo apt update && sudo apt install -y docker-ce=18.06.0~ce~3-0~debiancurl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list > /dev/null
sudo apt update && sudo apt install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectlsudo kubeadm init --pod-network-cidr=10.244.0.0/16You will see something like this:
Your Kubernetes master 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.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
  https://kubernetes.io/docs/concepts/cluster-administration/addons/
You can now join any number of machines by running the following on each node
as root:
  sudo kubeadm join 172.16.153.131:6443 --token bfvz2a.ie09qb8tj256t9tu --discovery-token-ca-cert-hash sha256:63572357080e3d0da5693baa7c20d19bcd804c9f639dd20338a3249793081fe5
Hint: Write down the kubeadm command, including the token en hash, it will come in handy when expanding the cluster
mkdir -p /home/meetup/.kube
sudo cp -i /etc/kubernetes/admin.conf /home/meetup/.kube/config
sudo chown meetup:users /home/meetup/.kube/configTake a look at your brand new kubernetes cluster:
kubectl get all --all-namespacesNotice that coredns will not start, cause the CNI (network) is missing.
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/bc79dd1505b0c8681ece4de4c0d86c5cd2643275/Documentation/kube-flannel.ymlTo make sure pods will also be scheduled on this node.
kubectl taint nodes --all node-role.kubernetes.io/master-As an ingress controller 'nginx-ingress' will be used. More information: https://kubernetes.github.io/ingress-nginx/deploy/
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/mandatory.yaml
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/provider/baremetal/service-nodeport.yamlMore info: https://github.com/tpryan/whack_a_pod
cd
git clone https://github.com/ljkoning/whack_a_pod.git(Note: original repo: git clone https://github.com/tpryan/whack_a_pod.git)
Make sure the context is set, since the make command will use it.
kubectl config set-context $(kubectl config current-context) --namespace=defaultCopy the Sample.properties to MAkefile.properties
cd ~/whack_a_pod
cp Sample.properties Makefile.propertiesEdit DOCKERREPO in Makefile.properties
nano Makefile.properties
DOCKERREPO=cloudowskiDeploy the game.
make deploy.genericAs you can see from the whack-a-pod directory in 'apps/ingress/ingress.generic.yaml', the hostname that is used by default is 'whackapod.example.com'.
To access the game, we need to add name to the hosts file of your windows jump host, with the IP of the node.
On windows, edit the file:
C:\Windows\System32\drivers\etc\hosts
To include this line (make sure to replace the IP address with your node address)
10.10.10.x1 whackapod.example.com
Lookup the NodePort on which the ingress controller is listening.
kubectl get service --namespace=ingress-nginxIn the below example it is: 32602
NAME            TYPE       CLUSTER-IP      EXTERNAL-IP   PORT(S)                      AGE
ingress-nginx   NodePort   10.100.75.185   <none>        80:32602/TCP,443:31226/TCP   20h
Go to the browser of your windows jumphost, and go to desired url:
- Full game - http://whackapod.example.com:32602
 - Less busy version - http://whackapod.example.com:32602/next.html
 - Advanced view - http://whackapod.example.com:32602/advanced.html
 
To clean up
make clean.generic- Login to the new node (host)
 
sudo apt install -y ca-certificates software-properties-common curl apt-transport-https
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/debian \
$(lsb_release -cs) \
stable"
sudo apt update && sudo apt install -y docker-ce=18.06.0~ce~3-0~debiancurl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list > /dev/null
sudo apt update && sudo apt install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectlsudo kubeadm join 172.16.153.131:6443 --token bfvz2a.ie09qb8tj256t9tu --discovery-token-ca-cert-hash sha256:63572357080e3d0da5693baa7c20d19bcd804c9f639dd20338a3249793081fe5With the following commands from the master (there is kubectl configured) you can check if the node is ready and the cluster is healthy.
kubectl get nodeskubectl get componentstatus- Kubectl auto-completion (tab tab)
 
source <(kubectl completion bash)Add this to '.bashrc' if you want this in every (new) session.