K8S集群部署

https://kubernetes.io/zh-cn/docs/setup/

Prepartion

swapoff -a

comment the swap mount

```systemctl --type swap``` and then ```systemctl mask dev-XXX.swap```


cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
overlay
br_netfilter
EOF

sudo modprobe overlay
sudo modprobe br_netfilter

cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward = 1
EOF

sudo sysctl –system


## Install Containerd

apt-get update
apt-get install ca-certificates curl gnupg lsb-release
mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg –dearmor -o /etc/apt/keyrings/docker.gpg
echo “deb [arch=$(dpkg –print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable” | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
apt-get update
apt install containerd


## Install K8S

apt-get install -y apt-transport-https ca-certificates curl
curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg

echo “deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main” | sudo tee /etc/apt/sources.list.d/kubernetes.list

apt update && apt-get install -y kubelet kubeadm kubectl
apt-mark hold kubelet kubeadm kubectl
systemctl restart containerd
systemctl enable –now containerd


## Create K8S Cluster


kubeadm init –pod-network-cidr=10.244.0.0/16


mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config


## Untaint the master node

for now we only have 1 node, so we need to untaint the master node

kubectl taint nodes –all node.kubernetes.io/not-ready-
kubectl taint nodes –all node-role.kubernetes.io/control-plane-


## Install Network Add-on

kubectl apply -f https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml (working with cidr=10.244.0.0/16 specified)

OR

kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml



## Get Join token

kubeadm token create –print-join-command


kubeadm join 192.168.88.3:6443 –token xxx –discovery-token-ca-cert-hash sha256:6dfa8feaaxxx


## Create dashboard service

kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.6.1/aio/deploy/recommended.yaml
kubectl proxy

http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/


kubectl delete clusterrolebinding kubernetes-dashboard -n kubernetes-dashboard
kubectl create clusterrolebinding kubernetes-dashboard -n kubernetes-dashboard –clusterrole=cluster-admin –serviceaccount=kubernetes-dashboard:kubernetes-dashboard
kubectl create token kubernetes-dashboard -n kubernetes-dashboard