我的K8S-v1.23.1安装笔记
我的K8S-v1.23.4安装笔记(2021-12-27)第1步:在VMware中安装1台CentOS 7,即master.镜像为:CentOS-7-x86_64-DVD-2009.iso第2步:给master添加两张网卡,分别走无线网,VMnet2网。注1:我的T490笔记本的固定无线IP为: 192.168.43.111注2:VMnet2网的IP在192.168.114.x网段。第3步:设置m
我的K8S-v1.23.1安装笔记
(2021-12-27)
第1步:在VMware中安装1台CentOS 7,即master.
镜像为:CentOS-7-x86_64-DVD-2009.iso
第2步:给master添加两张网卡,分别走无线网,VMnet2网。
注1:我的T490笔记本的固定无线IP为: 192.168.43.111
注2:VMnet2网的IP在192.168.114.x网段。
第3步:设置master的IP为:
注:由于未知的原因,有时需要跑一下open-internet.sh才能上互联网。
第4步:设置yum源
可参考下面这个文章:
请参见笔记:<< 2021-12-20_配置CentOS7 yum源(使用清华服务器).png>>
第5步:安装docker
第6步:复制master,为node1, node 2。
第7步:设置IP、主机名 (所有节点)
主机 | 无线网 | Vmnet2网 |
master | 192.168.43.209 | 192.168.114.209 |
node1 | 192.168.43.210 | 192.168.114.210 |
node2 | 192.168.43.211 | 192.168.114.211 |
注意:我的环境设置了两套网络,192.168.43.x用来上互联网,192.168.114.x用来跑k8s。
第8步:调整时区(所有节点)
使用tzselect命令,过程略。
注:用这个更好,重启也能有效。
timedatectl set-timezone 'Asia/Shanghai' |
第9步:设置ntp(所有节点)
过程略,请参考《OpenShift 3.6离线环境部署指南-20170910.docx》
第10步:关闭防火墙及selinux(所有节点)
所有节点确保防火墙关闭
systemctl stop firewalld
systemctl disable firewalld
第11步:关闭swap(所有节点)
第12步:调整CPU核心(master节点)
第13步:添加kubernetes.repo(所有节点)
注意:要关闭gpg检查。
第14步:安装k8s(所有节点)
yum install -y kubelet kubeadm kubectl
第15步:设置docker镜像源(所有节点)
第16步:初始化k8s(master节点)
# 初始化集群控制台 Control plane
# 失败了可以用 kubeadm reset 重置
kubeadm init \
--apiserver-advertise-address=192.168.114.209 \
--image-repository registry.aliyuncs.com/google_containers \
--kubernetes-version v1.23.4 \
--service-cidr=10.1.0.0/16 \
--pod-network-cidr=10.244.0.0/16
注意:要把最后生成两行复制下来,并把\删除,例如:
kubeadm join 192.168.114.209:6443 --token 9vg85i.i3fbqqn550xpgqit --discovery-token-ca-cert-hash sha256:647e8xxxx
第17步:复制授权文件(master节点)
# 复制授权文件,以便 kubectl 可以有权限访问集群
rm -rf $HOME/.kube
mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
第18步:安装flannel网络插件(master节点)(可选,也可以安装calico网络)
注意:
可能是因为我用的k8s, docker太新了,所以要用新一点的kube-flannel.yml文件,网上很多都是很旧的。加上那个https://raw.githubusercontent.com
不能访问,这个浪费了我一天时间。
最后,我从下面的地址下载,找一个可以使用的kube-flannel.yml:
https://codeload.github.com/flannel-io/flannel/zip/refs/tags/v0.16.0
--- apiVersion: policy/v1beta1 kind: PodSecurityPolicy metadata: name: psp.flannel.unprivileged annotations: seccomp.security.alpha.kubernetes.io/allowedProfileNames: docker/default seccomp.security.alpha.kubernetes.io/defaultProfileName: docker/default apparmor.security.beta.kubernetes.io/allowedProfileNames: runtime/default apparmor.security.beta.kubernetes.io/defaultProfileName: runtime/default spec: privileged: false volumes: - configMap - secret - emptyDir - hostPath allowedHostPaths: - pathPrefix: "/etc/cni/net.d" - pathPrefix: "/etc/kube-flannel" - pathPrefix: "/run/flannel" readOnlyRootFilesystem: false # Users and groups runAsUser: rule: RunAsAny supplementalGroups: rule: RunAsAny fsGroup: rule: RunAsAny # Privilege Escalation allowPrivilegeEscalation: false defaultAllowPrivilegeEscalation: false # Capabilities allowedCapabilities: ['NET_ADMIN', 'NET_RAW'] defaultAddCapabilities: [] requiredDropCapabilities: [] # Host namespaces hostPID: false hostIPC: false hostNetwork: true hostPorts: - min: 0 max: 65535 # SELinux seLinux: # SELinux is unused in CaaSP rule: 'RunAsAny' --- kind: ClusterRole apiVersion: rbac.authorization.k8s.io/v1 metadata: name: flannel rules: - apiGroups: ['extensions'] resources: ['podsecuritypolicies'] verbs: ['use'] resourceNames: ['psp.flannel.unprivileged'] - apiGroups: - "" resources: - pods verbs: - get - apiGroups: - "" resources: - nodes verbs: - 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-system --- apiVersion: v1 kind: ServiceAccount metadata: name: flannel namespace: kube-system --- kind: ConfigMap apiVersion: v1 metadata: name: kube-flannel-cfg namespace: kube-system 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-system 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: rancher/mirrored-flannelcni-flannel-cni-plugin:v1.0.0 command: - cp args: - -f - /flannel - /opt/cni/bin/flannel volumeMounts: - name: cni-plugin mountPath: /opt/cni/bin - name: install-cni image: quay.io/coreos/flannel:v0.15.1 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: quay.io/coreos/flannel:v0.15.1 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 volumeMounts: - name: run mountPath: /run/flannel - name: flannel-cfg mountPath: /etc/kube-flannel/ 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 |
注:quay.io被墙的解决办法,如下:
第19步:工作节点加入集群(node节点)
第20步:检查node, pod(master节点)
更多推荐
所有评论(0)