[//]: # (Confidential document)
[//]: # (01/05/2025)
[//]: # (v 1.7.3)


# Kubernetes  labs v1.7.3 - Architecture

## Lab1 : minikube

minikube quickly sets up a local Kubernetes cluster on macOS, Linux, and Windows. We proudly focus on helping application developers and new Kubernetes users.

- Install minikube
- Start a cluster
- Enable addons
- Access the Kubernetes dashboard

```
minikube start --driver=docker  --cni=cilium 
minikube status
kubectl get po -A
minikube addons list
minikube addons enable metrics-server
kubectl get pod,svc -n kube-system
kubectl top pods
minikube addons enable dashboard
minikube dashboard
minikube stop
minikube delete
```

## Lab2 : kubeadm 

```
sudo su
apt-get update
apt-get install -y apt-transport-https ca-certificates curl gpg
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.31/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.31/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list
apt-get update
apt-get install -y kubelet kubeadm
apt-mark hold kubelet kubeadm
systemctl enable --now kubelet
wget https://github.com/Mirantis/cri-dockerd/releases/download/v0.4.0/cri-dockerd_0.4.0.3-0.ubuntu-jammy_amd64.deb
chmod 644 /home/plb/cri-dockerd_0.4.0.3-0.ubuntu-jammy_amd64.deb
apt-get install ./cri-dockerd_0.4.0.3-0.ubuntu-jammy_amd64.deb 
swapoff -a
```

Install Master Node
```
sudo su 
swapon --show
swapoff -a
systemctl enable --now kubelet
kubeadm init --cri-socket unix:///var/run/cri-dockerd.sock --v 5 --node-name master

systemctl status kubelet
journalctl -xeu kubelet

export KUBECONFIG=/etc/kubernetes/admin.conf
helm repo add cilium https://helm.cilium.io/
helm repo add cilium https://helm.cilium.io/
helm install cilium cilium/cilium --version 1.17.3 --set operator.replicas=1 --namespace kube-system 

+ Control plane node isolation
```

Install Worker node
```
sudo  su
swapon --show
swapoff -a
systemctl enable --now kubelet
kubeadm join ... --cri-socket unix:///var/run/cri-dockerd.sock --v 5 --node-name worker 
```


Clean up Master Node
```
sudo su
export KUBECONFIG=/etc/kubernetes/admin.conf
kubectl drain worker --delete-emptydir-data --force --ignore-daemonsets
iptables -F && iptables -t nat -F && iptables -t mangle -F && iptables -X
kubectl delete node worker
kubeadm reset -f
systemctl stop kubelet
rm -rf /etc/kubernetes/ /var/lib/kubelet/ /var/lib/etcd /etc/cni /opt/cni
docker container rm -f $(docker ps -aq)
systemctl restart kubelet
systemctl restart docker
unset KUBECONFIG
```

Clean up Worker node

```
sudo su
iptables -F && iptables -t nat -F && iptables -t mangle -F && iptables -X
kubeadm reset -f
systemctl stop kubelet
rm -rf /etc/kubernetes/ /var/lib/kubelet/ /var/lib/etcd /etc/cni /opt/cni
docker container rm -f $(docker ps -aq)
systemctl restart docker
unset KUBECONFIG
```


## Lab3 Scheduler Affinity and anti-affinity
Modify the manifest to make sure the Pods are scheduled on diff Nodes

Deploy the Pod
```bash
kubectl apply -f manifests/pod-example.yaml
kubectl apply -f manifests/pod-backup-example.yaml
kubectl get pods
```



## Clean up

```
kubectl delete -f manifests/

```