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