Last active 1705433090

Kubernetes init

kubeadm-init.sh Raw
1swapoff /dev/xxx
2# disable in /etc/fstab also
3systemctl mask --now firewalld
4echo br_netfilter >> /etc/modules-load.d/kubernetes.conf
5modprobe br_netfilter
6sysctl -w net.ipv4.ip_forwarding=1 | tee -a /etc/sysctl.conf
7sysctl -w net.bridge.bridge-nf-call-iptables=1 | tee -a /etc/sysctl.conf
8sysctl -w net.bridge.bridge-nf-call-ip6tables=1 | tee -a /etc/sysctl.conf
9
10cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
11[kubernetes]
12name=Kubernetes
13baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-\$basearch
14enabled=1
15gpgcheck=1
16gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
17exclude=kubelet kubeadm kubectl
18EOF
19
20export OS=CentOS_8
21export VERSION=1.24
22curl -L -o /etc/yum.repos.d/devel:kubic:libcontainers:stable.repo https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/$OS/devel:kubic:libcontainers:stable.repo
23curl -L -o /etc/yum.repos.d/devel:kubic:libcontainers:stable:cri-o:$VERSION.repo https://download.opensuse.org/repositories/devel:kubic:libcontainers:stable:cri-o:$VERSION/$OS/devel:kubic:libcontainers:stable:cri-o:$VERSION.repo
24dnf makecache
25dnf install -y kubelet-1.24.0 kubeadm-1.24.0 kubectl-1.24.0 crio
26sudo setenforce 0
27sudo sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
28sudo systemctl enable --now kubelet crio
29kubeadm init --apiserver-advertise-address=10.75.254.1 --pod-network-cidr=10.244.0.0/16
30
31# Take note of the join command
32
33kubectl apply -f https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml
34kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.13.4/config/manifests/metallb-native.yaml
35
36kubectl create secret generic -n metallb-system memberlist --from-literal=secretkey="$(openssl rand -base64 128)"
37
38# change address pool below
39cat <<EOF>metallb-addresspool.yaml
40apiVersion: metallb.io/v1beta1
41kind: IPAddressPool
42metadata:
43 name: first-pool
44 namespace: metallb-system
45spec:
46 addresses:
47 - 192.168.1.101-192.168.1.199
48---
49apiVersion: metallb.io/v1beta1
50kind: L2Advertisement
51metadata:
52 name: example
53 namespace: metallb-system
54EOF
55
56kubectl apply -f metallb-addresspool.yaml