Ultima attività 1706077627

Install K8S on your home lab!

anduin's Avatar anduin ha revisionato questo gist 1706077627. Vai alla revisione

1 file changed, 1 insertion, 1 deletion

Install.sh

@@ -50,7 +50,7 @@ DEBIAN_FRONTEND=noninteractive sudo apt install kubeadm kubelet kubectl kubernet
50 50 # Init (Only on Master)
51 51 echo "Init K8S..."
52 52 sudo kubeadm config images pull
53 - sudo kubeadm init --pod-network-cidr=10.244.0.0/16
53 + sudo kubeadm init --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=10.64.50.111
54 54 read -p "Please copy the kubeadm join command above and run it on worker nodes. Press any key to continue..."
55 55
56 56 # Config (Only on Master)

anduin's Avatar anduin ha revisionato questo gist 1706076476. Vai alla revisione

1 file changed, 11 insertions, 2 deletions

Install.sh

@@ -69,8 +69,17 @@ sudo systemctl restart kubelet.service
69 69
70 70 # Test (Only on Master)
71 71 echo "Test K8S..."
72 - kubectl get nodes -o wide
73 - kubectl get pods --all-namespaces
72 + while [ "$(kubectl get nodes | grep -v "Ready" | wc -l)" -gt 1 ]; do
73 + echo "Waiting for all nodes to be ready..."
74 + kubectl get nodes -o wide
75 + sleep 5
76 + done
77 +
78 + while [ "$(kubectl get pods --all-namespaces | grep -v "Running" | wc -l)" -gt 1 ]; do
79 + echo "Waiting for all pods to be running..."
80 + kubectl get pods --all-namespaces -o wide
81 + sleep 5
82 + done
74 83
75 84 # Install Dashboard (Only on Master)
76 85 echo "Install dashboard..."

anduin's Avatar anduin ha revisionato questo gist 1706029588. Vai alla revisione

1 file changed, 27 insertions, 1 deletion

Install.sh

@@ -70,4 +70,30 @@ sudo systemctl restart kubelet.service
70 70 # Test (Only on Master)
71 71 echo "Test K8S..."
72 72 kubectl get nodes -o wide
73 - kubectl get pods --all-namespaces
73 + kubectl get pods --all-namespaces
74 +
75 + # Install Dashboard (Only on Master)
76 + echo "Install dashboard..."
77 + kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml
78 + kubectl create serviceaccount -n kubernetes-dashboard admin-user
79 + cat << EOF > rbac.yaml
80 + apiVersion: rbac.authorization.k8s.io/v1
81 + kind: ClusterRoleBinding
82 + metadata:
83 + name: admin-user
84 + roleRef:
85 + apiGroup: rbac.authorization.k8s.io
86 + kind: ClusterRole
87 + name: cluster-admin
88 + subjects:
89 + - kind: ServiceAccount
90 + name: admin-user
91 + namespace: kubernetes-dashboard
92 + EOF
93 + kubectl apply -f rbac.yaml
94 + rm rbac.yaml
95 + token=$(kubectl -n kubernetes-dashboard create token admin-user)
96 + echo "Dashboard token: $token"
97 + kubectl port-forward -n kubernetes-dashboard service/kubernetes-dashboard --address 0.0.0.0 10443:443
98 + hostname=$(hostname)
99 + echo "Dashboard URL: https://$hostname:10443"

anduin's Avatar anduin ha revisionato questo gist 1706027988. Vai alla revisione

1 file changed, 1 insertion, 1 deletion

Install.sh

@@ -2,7 +2,7 @@
2 2 # This script is to install Kubernetes on Ubuntu 22.04 LTS, with Calico as CNI
3 3 # This script used 10.244.0.0/16 as pod network CIDR. This network should not be used in your physical network.
4 4 # This script used Calico v3.27.0. You can change it to the latest version.
5 - # Reference: https://www.cherryservers.com/blog/install-kubernetes-on-ubuntu#step-2-set-up-hostnames
5 + # Reference: https://www.cherryservers.com/blog/install-kubernetes-on-ubuntu
6 6
7 7 DEBIAN_FRONTEND=noninteractive sudo apt update
8 8 DEBIAN_FRONTEND=noninteractive sudo apt install curl gnupg2 software-properties-common apt-transport-https ca-certificates -y

anduin's Avatar anduin ha revisionato questo gist 1706027982. Vai alla revisione

1 file changed, 1 insertion

Install.sh

@@ -2,6 +2,7 @@
2 2 # This script is to install Kubernetes on Ubuntu 22.04 LTS, with Calico as CNI
3 3 # This script used 10.244.0.0/16 as pod network CIDR. This network should not be used in your physical network.
4 4 # This script used Calico v3.27.0. You can change it to the latest version.
5 + # Reference: https://www.cherryservers.com/blog/install-kubernetes-on-ubuntu#step-2-set-up-hostnames
5 6
6 7 DEBIAN_FRONTEND=noninteractive sudo apt update
7 8 DEBIAN_FRONTEND=noninteractive sudo apt install curl gnupg2 software-properties-common apt-transport-https ca-certificates -y

anduin's Avatar anduin ha revisionato questo gist 1706027925. Vai alla revisione

1 file changed, 6 insertions, 2 deletions

Install.sh

@@ -6,6 +6,10 @@
6 6 DEBIAN_FRONTEND=noninteractive sudo apt update
7 7 DEBIAN_FRONTEND=noninteractive sudo apt install curl gnupg2 software-properties-common apt-transport-https ca-certificates -y
8 8
9 + echo "Disable swap..."
10 + sudo swapoff -a
11 + sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
12 +
9 13 echo "Uninstall Docker.ce..."
10 14 aiur() { arg="$( cut -d ' ' -f 2- <<< "$@" )" && curl -sL https://gitlab.aiursoft.cn/aiursoft/aiurscript/-/raw/master/$1.sh | sudo bash -s $arg; }
11 15 aiur uninstall/docker
@@ -30,11 +34,11 @@ EOF
30 34 sudo sysctl --system
31 35
32 36 echo "Prepare runtime to setup containerd..."
33 - sudo mkdir /etc/containerd
37 + sudo mkdir /etc/containerd > /dev/null 2>&1
34 38 sudo sh -c "containerd config default > /etc/containerd/config.toml"
35 39 sudo sed -i 's/ SystemdCgroup = false/ SystemdCgroup = true/' /etc/containerd/config.toml
36 40 sudo systemctl restart containerd.service
37 - sudo systemctl restart kubelet.service
41 + sudo systemctl restart kubelet.service > /dev/null 2>&1
38 42
39 43 echo "Install K8S..."
40 44 curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes.gpg --yes

anduin's Avatar anduin ha revisionato questo gist 1706027615. Vai alla revisione

1 file changed, 1 insertion, 1 deletion

Install.sh

@@ -37,7 +37,7 @@ sudo systemctl restart containerd.service
37 37 sudo systemctl restart kubelet.service
38 38
39 39 echo "Install K8S..."
40 - curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes.gpg
40 + curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes.gpg --yes
41 41 echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/kubernetes.gpg] http://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list
42 42 sudo apt update
43 43 DEBIAN_FRONTEND=noninteractive sudo apt install kubeadm kubelet kubectl kubernetes-cni -y

anduin's Avatar anduin ha revisionato questo gist 1706027455. Vai alla revisione

1 file changed, 9 insertions, 6 deletions

Install.sh

@@ -3,17 +3,17 @@
3 3 # This script used 10.244.0.0/16 as pod network CIDR. This network should not be used in your physical network.
4 4 # This script used Calico v3.27.0. You can change it to the latest version.
5 5
6 - # Prerequisites
7 6 DEBIAN_FRONTEND=noninteractive sudo apt update
8 7 DEBIAN_FRONTEND=noninteractive sudo apt install curl gnupg2 software-properties-common apt-transport-https ca-certificates -y
9 8
10 - # Docker
11 - echo "Install Docker..."
9 + echo "Uninstall Docker.ce..."
12 10 aiur() { arg="$( cut -d ' ' -f 2- <<< "$@" )" && curl -sL https://gitlab.aiursoft.cn/aiursoft/aiurscript/-/raw/master/$1.sh | sudo bash -s $arg; }
13 11 aiur uninstall/docker
12 + sudo apt autoremove -y
13 +
14 + echo "Install Docker.io..."
14 15 DEBIAN_FRONTEND=noninteractive sudo apt install docker.io -y
15 16
16 - # Network
17 17 echo "Prepare network..."
18 18 cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
19 19 overlay
@@ -29,7 +29,6 @@ net.ipv4.ip_forward = 1
29 29 EOF
30 30 sudo sysctl --system
31 31
32 - # Runtime
33 32 echo "Prepare runtime to setup containerd..."
34 33 sudo mkdir /etc/containerd
35 34 sudo sh -c "containerd config default > /etc/containerd/config.toml"
@@ -37,23 +36,26 @@ sudo sed -i 's/ SystemdCgroup = false/ SystemdCgroup = true/' /etc/containerd/co
37 36 sudo systemctl restart containerd.service
38 37 sudo systemctl restart kubelet.service
39 38
40 - # K8S
39 + echo "Install K8S..."
41 40 curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes.gpg
42 41 echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/kubernetes.gpg] http://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list
43 42 sudo apt update
44 43 DEBIAN_FRONTEND=noninteractive sudo apt install kubeadm kubelet kubectl kubernetes-cni -y
45 44
46 45 # Init (Only on Master)
46 + echo "Init K8S..."
47 47 sudo kubeadm config images pull
48 48 sudo kubeadm init --pod-network-cidr=10.244.0.0/16
49 49 read -p "Please copy the kubeadm join command above and run it on worker nodes. Press any key to continue..."
50 50
51 51 # Config (Only on Master)
52 + echo "Config K8S..."
52 53 mkdir -p $HOME/.kube
53 54 sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
54 55 sudo chown $(id -u):$(id -g) $HOME/.kube/config
55 56
56 57 # Calico (Only on Master)
58 + echo "Install Calico..."
57 59 kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.27.0/manifests/tigera-operator.yaml
58 60 curl https://raw.githubusercontent.com/projectcalico/calico/v3.27.0/manifests/custom-resources.yaml -O
59 61 sed -i 's/cidr: 192\.168\.0\.0\/16/cidr: 10\.244\.0\.0\/16/' custom-resources.yaml
@@ -61,5 +63,6 @@ kubectl create -f custom-resources.yaml
61 63 sudo systemctl restart kubelet.service
62 64
63 65 # Test (Only on Master)
66 + echo "Test K8S..."
64 67 kubectl get nodes -o wide
65 68 kubectl get pods --all-namespaces

anduin's Avatar anduin ha revisionato questo gist 1706027361. Vai alla revisione

1 file changed, 2 insertions

Install.sh

@@ -9,6 +9,8 @@ DEBIAN_FRONTEND=noninteractive sudo apt install curl gnupg2 software-properties-
9 9
10 10 # Docker
11 11 echo "Install Docker..."
12 + aiur() { arg="$( cut -d ' ' -f 2- <<< "$@" )" && curl -sL https://gitlab.aiursoft.cn/aiursoft/aiurscript/-/raw/master/$1.sh | sudo bash -s $arg; }
13 + aiur uninstall/docker
12 14 DEBIAN_FRONTEND=noninteractive sudo apt install docker.io -y
13 15
14 16 # Network

anduin's Avatar anduin ha revisionato questo gist 1706027027. Vai alla revisione

1 file changed, 63 insertions

Install.sh(file creato)

@@ -0,0 +1,63 @@
1 + #/bin/bash
2 + # This script is to install Kubernetes on Ubuntu 22.04 LTS, with Calico as CNI
3 + # This script used 10.244.0.0/16 as pod network CIDR. This network should not be used in your physical network.
4 + # This script used Calico v3.27.0. You can change it to the latest version.
5 +
6 + # Prerequisites
7 + DEBIAN_FRONTEND=noninteractive sudo apt update
8 + DEBIAN_FRONTEND=noninteractive sudo apt install curl gnupg2 software-properties-common apt-transport-https ca-certificates -y
9 +
10 + # Docker
11 + echo "Install Docker..."
12 + DEBIAN_FRONTEND=noninteractive sudo apt install docker.io -y
13 +
14 + # Network
15 + echo "Prepare network..."
16 + cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
17 + overlay
18 + br_netfilter
19 + EOF
20 + sudo modprobe overlay
21 + sudo modprobe br_netfilter
22 + # sysctl params required by setup, params persist across reboots
23 + cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
24 + net.bridge.bridge-nf-call-iptables = 1
25 + net.bridge.bridge-nf-call-ip6tables = 1
26 + net.ipv4.ip_forward = 1
27 + EOF
28 + sudo sysctl --system
29 +
30 + # Runtime
31 + echo "Prepare runtime to setup containerd..."
32 + sudo mkdir /etc/containerd
33 + sudo sh -c "containerd config default > /etc/containerd/config.toml"
34 + sudo sed -i 's/ SystemdCgroup = false/ SystemdCgroup = true/' /etc/containerd/config.toml
35 + sudo systemctl restart containerd.service
36 + sudo systemctl restart kubelet.service
37 +
38 + # K8S
39 + curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes.gpg
40 + echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/kubernetes.gpg] http://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list
41 + sudo apt update
42 + DEBIAN_FRONTEND=noninteractive sudo apt install kubeadm kubelet kubectl kubernetes-cni -y
43 +
44 + # Init (Only on Master)
45 + sudo kubeadm config images pull
46 + sudo kubeadm init --pod-network-cidr=10.244.0.0/16
47 + read -p "Please copy the kubeadm join command above and run it on worker nodes. Press any key to continue..."
48 +
49 + # Config (Only on Master)
50 + mkdir -p $HOME/.kube
51 + sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
52 + sudo chown $(id -u):$(id -g) $HOME/.kube/config
53 +
54 + # Calico (Only on Master)
55 + kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.27.0/manifests/tigera-operator.yaml
56 + curl https://raw.githubusercontent.com/projectcalico/calico/v3.27.0/manifests/custom-resources.yaml -O
57 + sed -i 's/cidr: 192\.168\.0\.0\/16/cidr: 10\.244\.0\.0\/16/' custom-resources.yaml
58 + kubectl create -f custom-resources.yaml
59 + sudo systemctl restart kubelet.service
60 +
61 + # Test (Only on Master)
62 + kubectl get nodes -o wide
63 + kubectl get pods --all-namespaces
Più nuovi Più vecchi