Kubernetes
kube 集群安装
2023-03-28 22:50:03
20 分钟阅读
8962 字
这片只是我在本地虚拟机安装 Kube 集群时随手记录的一些内容,并不是完整的文章。
虚拟机配置 更新 Ubuntu 源 (ARM64) 1 sudo vim /etc/apt/sources.list
1 2 3 4 5 6 7 8 9 10 11 12 13 deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-updates main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-backports main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-security main restricted universe multiverse
修改 root 密码并允许使用 root 帐号进行 ssh 登陆 1 2 3 4 5 sudo passwd root su root apt install -y vim sudo vi /etc/ssh/sshd_config service sshd restart
配置静态 IP 1 2 vim /etc/netplan/00-installer-config.yaml
1 2 3 4 5 6 7 8 9 10 11 12 13 network: version: 2 renderer: networkd ethernets: enp0s5: dhcp4: no addresses: - 192.168 .1 .174 /24 routes: - to: default via: 192.168 .1 .1 nameservers: addresses: [114.114 .114 .114 ,255.255 .255 .0 ]
1 sudo systemctl restart systemd-resolved.service
防火墙 1 2 sudo ufw disable && sudo ufw status sudo ufw enable
集群规划 1 2 192.168.1.171 kube-n1 192.168.1.172 kube-n2
设置主机名 1 2 hostnamectl set-hostname master hostnamectl set-hostname node1
同步 host 文件 1 2 3 vim /etc/hosts 192.168.1.171 kube-n1 192.168.1.172 kube-n2
禁用 swap 1 swapoff -a && sed -ri 's/.*swap.*/#&/' /etc/fstab
设置内核模块 1 2 3 4 5 6 7 vim /etc/modules-load.d/containerd.conf overlay br_netfilter modprobe overlay modprobe br_netfilter
为 Kubernetes 设置 内核 1 2 3 4 5 sudo tee /etc/sysctl.d/kubernetes.conf <<EOF net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 net.ipv4.ip_forward = 1 EOF
安装 containerd 1 sudo apt install -y curl gnupg2 software-properties-common apt-transport-https ca-certificates
1 sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmour -o /etc/apt/trusted.gpg.d/docker.gpg
1 sudo add-apt-repository "deb [arch=arm64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
1 https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg
1 curl -s https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | sudo gpg --dearmour -o /etc/apt/trusted.gpg.d/kubernetes-xenial.gpg
1 sudo apt-add-repository "deb https://mirrors.tuna.tsinghua.edu.cn/kubernetes/apt kubernetes-xenial main"
1 2 3 4 5 6 7 8 9 cat << EOF > kubernetes.repo [kubernetes] name=Kubernetes baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-aarch64 enabled=1 gpgcheck=0 repo_gpgcheck=0 gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg EOF
1 2 3 4 5 6 7 8 9 deb [ arch=arm64,armhf ] https://mirrors.tuna.tsinghua.edu.cn/debian/ stretch main contrib non-free # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ stretch main contrib non-free deb [ arch=arm64,armhf ] https://mirrors.tuna.tsinghua.edu.cn/debian/ stretch-updates main contrib non-free # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ stretch-updates main contrib non-free deb [ arch=arm64,armhf ] https://mirrors.tuna.tsinghua.edu.cn/debian/ stretch-backports main contrib non-free # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ stretch-backports main contrib non-free deb [ arch=arm64,armhf ] https://mirrors.tuna.tsinghua.edu.cn/debian-security/ stretch/updates main contrib non-free # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security/ stretch/updates main contrib non-free # deb [ arch=arm64,armhf ] https://mirrors.tuna.tsinghua.edu.cn/debian/ sid main contrib non-free
命令 1 kubeadm reset -f && rm -rf /etc/kubernetes/
1 2 kubeadm join 192.168.1.173:6443 --token q8sbfq.8hca0yxui0uh7bcb \ --discovery-token-ca-cert-hash sha256:3feeffbb7c55e962e523a05015f9d133677a71ae4eb95e616ac23476f375a2c7
1 2 kubeadm join 192.168.1.210:6443 --token 78dj3e.tj23w5i0cosg4vxe \ --discovery-token-ca-cert-hash sha256:885aa870800e6418b1ecc14dd8622bae5f91991e6b1191c4c9bfb6dbd993669a
问题记录:
1 2 root@kube-n1:/ The connection to the server 192.168.1.173:6443 was refused - did you specify the right host or port?
解决方法:
解决方法:参考该文章
1 2 3 4 kubeadm init \ --apiserver-advertise-address=192.168.1.116 \ --pod-network-cidr=192.168.1.116/16 \ --image-repository registry.aliyuncs.com/google_containers
vim /etc/netplan/xxx.yml
1 2 3 4 5 6 7 8 9 10 11 12 13 network: version: 2 renderer: networkd ethernets: enp0s5: dhcp4: no addresses: - 192.168.1.174/24 routes: - to: default via: 192.168.1.1 nameservers: addresses: [114.114.114.114,255.255.255.0]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 --- kind: Namespace apiVersion: v1 metadata: name: kube-flannel labels: pod-security.kubernetes.io/enforce: privileged --- kind: ClusterRole apiVersion: rbac.authorization.k8s.io/v1 metadata: name: flannel rules: - apiGroups: - "" resources: - pods verbs: - get - apiGroups: - "" resources: - nodes verbs: - get - list - watch - apiGroups: - "" resources: - nodes/status verbs: - patch --- kind: ClusterRoleBinding apiVersion: rbac.authorization.k8s.io/v1 metadata: name: flannel roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: flannel subjects: - kind: ServiceAccount name: flannel namespace: kube-flannel --- apiVersion: v1 kind: ServiceAccount metadata: name: flannel namespace: kube-flannel --- kind: ConfigMap apiVersion: v1 metadata: name: kube-flannel-cfg namespace: kube-flannel labels: tier: node app: flannel data: cni-conf.json: | { "name": "cbr0", "cniVersion": "0.3.1", "plugins": [ { "type": "flannel", "delegate": { "hairpinMode": true, "isDefaultGateway": true } }, { "type": "portmap", "capabilities": { "portMappings": true } } ] } net-conf.json: | { "Network": "10.244.0.0/16", "Backend": { "Type": "vxlan" } } --- apiVersion: apps/v1 kind: DaemonSet metadata: name: kube-flannel-ds namespace: kube-flannel labels: tier: node app: flannel spec: selector: matchLabels: app: flannel template: metadata: labels: tier: node app: flannel spec: affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - key: kubernetes.io/os operator: In values: - linux hostNetwork: true priorityClassName: system-node-critical tolerations: - operator: Exists effect: NoSchedule serviceAccountName: flannel initContainers: - name: install-cni-plugin image: docker.io/rancher/mirrored-flannelcni-flannel-cni-plugin:v1.1.0 command: - cp args: - -f - /flannel - /opt/cni/bin/flannel volumeMounts: - name: cni-plugin mountPath: /opt/cni/bin - name: install-cni image: docker.io/rancher/mirrored-flannelcni-flannel:v0.20.2 command: - cp args: - -f - /etc/kube-flannel/cni-conf.json - /etc/cni/net.d/10-flannel.conflist volumeMounts: - name: cni mountPath: /etc/cni/net.d - name: flannel-cfg mountPath: /etc/kube-flannel/ containers: - name: kube-flannel image: docker.io/rancher/mirrored-flannelcni-flannel:v0.20.2 command: - /opt/bin/flanneld args: - --ip-masq - --kube-subnet-mgr resources: requests: cpu: "100m" memory: "50Mi" limits: cpu: "100m" memory: "50Mi" securityContext: privileged: false capabilities: add: ["NET_ADMIN" , "NET_RAW" ] env: - name: POD_NAME valueFrom: fieldRef: fieldPath: metadata.name - name: POD_NAMESPACE valueFrom: fieldRef: fieldPath: metadata.namespace - name: EVENT_QUEUE_DEPTH value: "5000" volumeMounts: - name: run mountPath: /run/flannel - name: flannel-cfg mountPath: /etc/kube-flannel/ - name: xtables-lock mountPath: /run/xtables.lock volumes: - name: run hostPath: path: /run/flannel - name: cni-plugin hostPath: path: /opt/cni/bin - name: cni hostPath: path: /etc/cni/net.d - name: flannel-cfg configMap: name: kube-flannel-cfg - name: xtables-lock hostPath: path: /run/xtables.lock type: FileOrCreate
1 2 3 4 5 $ timedatectl set-timezone Asia/Shanghai $ chronyc -a makestep 200 OK