类型 | 版本 |
---|---|
操作系统 | CentOS Linux release 7.6.1810 (AltArch) |
内核 | Linux master 4.18.0-80.7.2.el7.aarch64 |
硬件配置 | 8核16G内存 * 2台 |
计算机名 | master、node1 |
K8S版本 | 1.14.2 |
计算机名 | 公网IP | 私网IP |
---|---|---|
master | 116.63.180.97 | 192.168.0.113 |
node1 | 116.63.177.54 | 192.168.0.226 |
说明:
- 搭建K8s集群,每台节点均需要按照文档安装Docker及K8s的全部组件。
- 为验证集群搭建功能,至少需要两个节点。如果要验证亲和性调度功能,至少需要三台节点,安装配置工作在每台节点都需要执行。
- Master为集群管理节点,node1为集群计算节点。
2021/11/25 华为云镜像仓库BUG,将ARM镜像全部删除了,大家可以配置阿里云
阿里云源
cat < /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-aarch64/
enabled=1
gpgcheck=1
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
华为云源
cat < /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.huaweicloud.com/kubernetes/yum/repos/kubernetes-el7-aarch64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=http://mirrors.huaweicloud.com/kubernetes/yum/doc/yum-key.gpg
http://mirrors.huaweicloud.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
说明:
若没有找到需要的k8s版本,可自行配置阿里yum源
yum makecache
主节点和计算节点都需要安装配置K8s。
yum install -y yum-utils
yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
要安装特定版本的Docker Engine,可以先通过命名查看存储库,列出可用版本,然后选择并安装:
yum list docker-ce --showduplicates | sort -r
yum list docker-ce-cli --showduplicates | sort -r
然后根据版本号安装(本文选择),例如:
yum install docker-ce-18.09.9-3.el7 docker-ce-cli-18.09.9-3.el7 containerd.io
也可以安装最新版,例如直接使用方式,本文选择的不是最新版本,安装的是指定版本18.09
yum install docker-ce docker-ce-cli containerd.io
systemctl start docker
systemctl enable docker
sysctl -w net.bridge.bridge-nf-call-iptables=1
swapoff -a
cp -p /etc/fstab /etc/fstab.bak$(date '+%Y%m%d%H%M%S')
sed -i "s/\/dev\/mapper\/centos-swap/\#\/dev\/mapper\/centos-swap/g" /etc/fstab
2021/11/25 华为云镜像仓库BUG,指定版本
阿里云镜像
yum install -y kubelet-1.14.2 kubectl-1.14.2 kubeadm-1.14.2 kubernetes-cni
华为云镜像
yum install -y kubelet kubeadm kubectl kubernetes-cni
rpm -qa | grep kubelet
rpm -qa | grep kubeadm
rpm -qa | grep kubectl
rpm -qa | grep kubernetes-cni
例如看到如下内容代表安装成功
[root@master aarch64]# rpm -qa | grep kubelet
kubelet-1.14.2-0.aarch64
[root@master aarch64]# rpm -qa | grep kubeadm
kubeadm-1.14.2-0.aarch64
[root@master aarch64]# rpm -qa | grep kubectl
kubectl-1.14.2-0.aarch64
[root@master aarch64]# rpm -qa | grep kubernetes-cn
kubernetes-cni-0.7.5-0.aarch64
echo "net.bridge.bridge-nf-call-iptables=1" > /etc/sysctl.d/k8s.conf
systemctl enable kubelet
kubeadm config images list
[root@master aarch64]# kubeadm config images list
I1208 09:21:05.327540 2544 version.go:96] could not fetch a Kubernetes version from the internet: unable to get URL "https://dl.k8s.io/release/stable-1.txt": Get https://storage.googleapis.com/kubernetes-release/release/stable-1.txt: net/http: request canceled (Client.Timeout exceeded while awaiting headers)
I1208 09:21:05.327591 2544 version.go:97] falling back to the local client version: v1.14.2
k8s.gcr.io/kube-apiserver:v1.14.2
k8s.gcr.io/kube-controller-manager:v1.14.2
k8s.gcr.io/kube-scheduler:v1.14.2
k8s.gcr.io/kube-proxy:v1.14.2
k8s.gcr.io/pause:3.1
k8s.gcr.io/etcd:3.3.10
k8s.gcr.io/coredns:1.3.1
K8s所需镜像版本有可能会变动,因此查看列表并以此匹配需要下载的Docker镜像,文档中的镜像版本仅做参考。
切忌直接把非arm架构机器上的镜像直接复制过来使用
命令如下所示
docker pull docker.io/mirrorgooglecontainers/kube-apiserver-arm64:v1.14.2
docker pull docker.io/mirrorgooglecontainers/kube-controller-manager-arm64:v1.14.2
docker pull docker.io/mirrorgooglecontainers/kube-scheduler-arm64:v1.14.2
docker pull docker.io/mirrorgooglecontainers/kube-proxy-arm64:v1.14.2
docker pull docker.io/mirrorgooglecontainers/pause-arm64:3.1
docker pull docker.io/mirrorgooglecontainers/etcd-arm64:3.3.10
docker pull docker.io/coredns/coredns:1.3.1
下载完成后可以查看本地镜像
[root@master aarch64]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mirrorgooglecontainers/kube-proxy-arm64 v1.14.2 5227f1c3c8a7 19 months ago 82.7MB
mirrorgooglecontainers/kube-apiserver-arm64 v1.14.2 091f78b1b081 19 months ago 207MB
mirrorgooglecontainers/kube-controller-manager-arm64 v1.14.2 e0fa3d206e49 19 months ago 155MB
mirrorgooglecontainers/kube-scheduler-arm64 v1.14.2 485238b2c4a5 19 months ago 82.2MB
coredns/coredns 1.3.1 7e8edeee9a1e 23 months ago 37.4MB
mirrorgooglecontainers/etcd-arm64 3.3.10 ad99d3ead043 2 years ago 300MB
mirrorgooglecontainers/pause-arm64 3.1 6cf7c80fe444 2 years ago 525kB
docker tag mirrorgooglecontainers/kube-apiserver-arm64:v1.14.2 k8s.gcr.io/kube-apiserver:v1.14.2
docker tag mirrorgooglecontainers/kube-controller-manager-arm64:v1.14.2 k8s.gcr.io/kube-controller-manager:v1.14.2
docker tag mirrorgooglecontainers/kube-scheduler-arm64:v1.14.2 k8s.gcr.io/kube-scheduler:v1.14.2
docker tag mirrorgooglecontainers/kube-proxy-arm64:v1.14.2 k8s.gcr.io/kube-proxy:v1.14.2
docker tag mirrorgooglecontainers/pause-arm64:3.1 k8s.gcr.io/pause:3.1
docker tag mirrorgooglecontainers/etcd-arm64:3.3.10 k8s.gcr.io/etcd:3.3.10
docker tag coredns/coredns:1.3.1 k8s.gcr.io/coredns:1.3.1
说明:
需要将镜像repository修改与kubeadm列出的镜像名保持一致。
docker images | grep k8s
[root@master aarch64]# docker images | grep k8s
k8s.gcr.io/kube-apiserver v1.14.2 091f78b1b081 19 months ago 207MB
k8s.gcr.io/kube-controller-manager v1.14.2 e0fa3d206e49 19 months ago 155MB
k8s.gcr.io/kube-scheduler v1.14.2 485238b2c4a5 19 months ago 82.2MB
k8s.gcr.io/kube-proxy v1.14.2 5227f1c3c8a7 19 months ago 82.7MB
k8s.gcr.io/coredns 1.3.1 7e8edeee9a1e 23 months ago 37.4MB
k8s.gcr.io/etcd 3.3.10 ad99d3ead043 2 years ago 300MB
k8s.gcr.io/pause 3.1 6cf7c80fe444 2 years ago 525kB
命令如下所示
docker rmi mirrorgooglecontainers/kube-apiserver-arm64:v1.14.2
docker rmi mirrorgooglecontainers/kube-controller-manager-arm64:v1.14.2
docker rmi mirrorgooglecontainers/kube-scheduler-arm64:v1.14.2
docker rmi mirrorgooglecontainers/kube-proxy-arm64:v1.14.2
docker rmi mirrorgooglecontainers/pause-arm64:3.1
docker rmi mirrorgooglecontainers/etcd-arm64:3.3.10
docker rmi coredns/coredns:1.3.1
删除后再次查看本地镜像
[root@master aarch64]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
k8s.gcr.io/kube-scheduler v1.14.2 485238b2c4a5 19 months ago 82.2MB
k8s.gcr.io/kube-proxy v1.14.2 5227f1c3c8a7 19 months ago 82.7MB
k8s.gcr.io/kube-apiserver v1.14.2 091f78b1b081 19 months ago 207MB
k8s.gcr.io/kube-controller-manager v1.14.2 e0fa3d206e49 19 months ago 155MB
k8s.gcr.io/coredns 1.3.1 7e8edeee9a1e 23 months ago 37.4MB
k8s.gcr.io/etcd 3.3.10 ad99d3ead043 2 years ago 300MB
k8s.gcr.io/pause 3.1 6cf7c80fe444 2 years ago 525kB
主节点和计算节点都需要配置hosts文件。
执行vi /etc/hosts命令,修改hosts文件,添加集群所有节点的ip及hostname信息。
192.168.0.113 master master
192.168.0.226 node1 node1
每台节点的/etc/hosts文件都要修改。
说明:重复搭建集群时,请先执行kubeadm reset命令,清除旧的K8s集群设置。
在主节点上执行集群初始化命令。
kubeadm init --kubernetes-version=1.14.2 --service-cidr=10.1.0.0/16 --pod-network-cidr=10.244.0.0/16
当看到如下信息时代表初始化成功
Your Kubernetes control-plane has initialized successfully!
To start using your cluster, you need to run the following as a regular user:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
https://kubernetes.io/docs/concepts/cluster-administration/addons/
Then you can join any number of worker nodes by running the following on each as root:
kubeadm join 192.168.0.113:6443 --token all7y6.hxs2yemaucku9dct \
--discovery-token-ca-cert-hash sha256:7e1b11d2715fd87d8aeec9a1924c87b68d36da35392ccee57b0581993dfeb821
黄框信息表示主节点配置集群需要执行的命令,红框信息表示计算节点加入集群的token命令,请保存该段命令。
说明:
计算节点不需要执行集群初始化操作。
如果在主节点初始化的时候提示:
/proc/sys/net/bridge/bridge-nf-call-iptables contents are not set to 1
可以通过执行echo 1 > /proc/sys/net/bridge/bridge-nf-call-iptables命令将其置为1(vim不可修改此文件)。执行该操作时,建议排查是否有配置代理(执行env查看),避免kubeadm init初始化超时失败,删除代理的操作:
export -n http_proxy
export -n https_proxy
export -n no_proxy
--pod-network-cidr > 选项用于指定kubernetes网络可以使用的IP地址段,由于后续使用Flannel网络插件,该插件固定使用的IP段为:10.244.0.0/16 。
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
export KUBECONFIG=/etc/kubernetes/admin.conf
kubectl get node
[root@master aarch64]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
master NotReady master 97s v1.14.2
该信息在成功初始化主节点后生成并打印,集群信息如下所示:
kubeadm join 192.168.0.113:6443 --token all7y6.hxs2yemaucku9dct \
--discovery-token-ca-cert-hash sha256:7e1b11d2715fd87d8aeec9a1924c87b68d36da35392ccee57b0581993dfeb821
注意:
该token命令可以用于二十四小时内计算节点加入集群,若token超时,可在K8S主节点通过kubeadm token create --print-join-command命令进行重新生成
计算节点执行
kubeadm join 192.168.0.113:6443 --token all7y6.hxs2yemaucku9dct \
--discovery-token-ca-cert-hash sha256:7e1b11d2715fd87d8aeec9a1924c87b68d36da35392ccee57b0581993dfeb821
[root@master opt]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
master Ready master 3h7m v1.14.2
node1 NotReady 83s v1.14.2
systemctl status kubelet
主节点
子节点
当前版本1.14版本执行(如果无法下载,可以查看网盘附件进行本地化安装,下载地址:百度网盘 请输入提取码 提取码:1fsh)
kubectl apply -f https://gitee.com/mirrors/flannel/blob/master/Documentation/kube-flannel-old.yaml
注意:对于 Kubernetes 版本 v1.17+
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
[root@master opt]# kubectl get pod -n kube-system
NAME READY STATUS RESTARTS AGE
coredns-fb8b8dccf-sgzqj 1/1 Running 0 38m
coredns-fb8b8dccf-xpx5x 1/1 Running 0 38m
etcd-master 1/1 Running 0 37m
kube-apiserver-master 1/1 Running 0 37m
kube-controller-manager-master 1/1 Running 0 37m
kube-flannel-ds-arm64-wxc6f 1/1 Running 0 98s
kube-proxy-tzb4r 1/1 Running 0 38m
kube-scheduler-master 1/1 Running 0 37m
这样我们K8S集群就搭建完成了。
主节点上操作即可
生成证书请求的key
openssl genrsa -out dashboard.key 2048
生成证书请求
openssl req -new -out dashboard.csr -key dashboard.key -subj '/CN='
生成自签证书
openssl x509 -days 3650 -req -in dashboard.csr -signkey dashboard.key -out dashboard.crt
这里指定了过期时间3650天,默认365天
(文件下载地址:链接:百度网盘 请输入提取码 提取码:1fsh)
根据官方文件做了微调:
- 把cert注释掉,使用待会自己创建的cert,因为默认的证书有问题;
- 把dashboard访问方式改为NodePort,端口是31234,访问时用pod所在主机的ip加端口号即可访问;
- imagePullPolicy改为IfNotPresent,当本地找不到镜像时才从网上拉取;
注意查看镜像路径是否有效,如果无效,自行百度查找镜像源,或者到别的地方把镜像下载到本地,然后把tag改成和yaml文件中的image一致- arm镜像源修改kubernetesui/metrics-scraper-arm64:v1.0.6和kubernetesui/dashboard-arm64:v2.0.5
kubectl apply -f /opt/kubernetes-dashboard.yaml
kubectl create secret generic kubernetes-dashboard-certs --from-file=/opt/dashboard.key --from-file=/opt/dashboard.crt -n kubernetes-dashboard
一般经过以上步骤就可以访问dashboard,可以跳过这一步了,但如果此时仍不能访问,pod不是处于"running"状态,可以删除kubenetes-dashboard相关的pod,让kubelet自动生成一个新的可运行的pod
查看kubernetes-dashboard的pod名
kubectl get pods -n kubernetes-dashboard
删除该pod:
kubectl delete pod -n kubernetes-dashboard
正确结果
[root@master /]# kubectl get pod -n kubernetes-dashboard
NAME READY STATUS RESTARTS AGE
dashboard-metrics-scraper-57c8667f5c-92fls 1/1 Running 0 5h9m
kubernetes-dashboard-69d48fd659-bw7zb 1/1 Running 0 5h9m
kubectl create serviceaccount admin-user -n kubernetes-dashboard
kubectl create clusterrolebinding admin-user --clusterrole=cluster-admin --serviceaccount=kubernetes-dashboard:admin-user
kubectl -n kubernetes-dashboard describe secret $(kubectl -n kubernetes-dashboard get secret | grep admin-user | awk '{print $1}')
复制生成的token值即可
[root@master opt]# kubectl -n kubernetes-dashboard describe secret $(kubectl -n kubernetes-dashboard get secret | grep admin-user | awk '{print $1}')
Name: admin-user-token-64tjt
Namespace: kubernetes-dashboard
Labels:
Annotations: kubernetes.io/service-account.name: admin-user
kubernetes.io/service-account.uid: c882f015-39ca-11eb-9396-fa163ec97a54
Type: kubernetes.io/service-account-token
Data
====
ca.crt: 1025 bytes
namespace: 20 bytes
token: eyJhbGciOiJSUzI1NiIsImtpZCI6IiJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlcm5ldGVzLWRhc2hib2FyZCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJhZG1pbi11c2VyLXRva2VuLTY0dGp0Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQubmFtZSI6ImFkbWluLXVzZXIiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC51aWQiOiJjODgyZjAxNS0zOWNhLTExZWItOTM5Ni1mYTE2M2VjOTdhNTQiLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6a3ViZXJuZXRlcy1kYXNoYm9hcmQ6YWRtaW4tdXNlciJ9.nK8gspJ8DAMzrOesHC-CGvjaYKAtahUCB9L1eQTbaeCXv-8ZT-8HVBzzCTk20XnAG30yPwOD80x_MBCksSgaw7QkImNlZVcNM3JXmaNvxFTObeg9aY_Lgdbs7r4hfAMKZd2wi1G3BaNbfAWnWxlecbOXTMYBL5PI6h5oJSuR6Fgm0IEdRT6diI_uaoan-Mqmvm_VKvj6tMl1xTqczTgnp0Hv5kwJvT0lOYx13nhjix-hfo0B2UaSGDnLcyFLrzAIOfKuAlFQMwcJndgs7hz_x7CM-UpfOvCg4oVrWkHAlspOfxRVflHXjfexUGnjGq2Rywph5h4godbTPwhLwJ4tcg
访问我们master地址,通过浏览器访问https://IP:31234,点击继续访问
输入token值
即可看到kubernetes-dashboard UI界面
UI查看节点信息
注意:
下列步骤仅仅指导用户如何手动卸载K8s组件,请勿在正常的部署过程中执行。
清空K8s集群设置。
在卸载K8s组件前,先执行kubeadm reset命令,清空K8s集群设置。
卸载管理组件。
yum erase -y kubelet kubectl kubeadm kubernetes-cni
删除基础组件镜像。
基础组件通过Docker镜像部署,因此只需要强制删除对应镜像即可卸载。
docker rmi -f k8s.gcr.io/kube-apiserver:v1.15.1
docker rmi -f k8s.gcr.io/kube-controller-manager:v1.15.1
docker rmi -f k8s.gcr.io/kube-scheduler:v1.15.1
docker rmi -f k8s.gcr.io/kube-proxy:v1.15.1
docker rmi -f k8s.gcr.io/pause:3.1
docker rmi -f k8s.gcr.io/etcd:3.3.10
docker rmi -f k8s.gcr.io/coredns:1.3.1
0/1 nodes are available: 1 node(s) had taints that the pod didn't tolerate.
答:是因为默认kubernetes默认不让pod部署到master节点,但是我在测试环境只有一个节点也是master节点,需要允许master节点部署pod
kubectl taint nodes --all node-role.kubernetes.io/master-
如果想要禁止,则执行以下命令
kubectl taint nodes k8s node-role.kubernetes.io/master=true:NoSchedule
答:需要安装Flannel后状态才能变成Ready。
(转发请注明出处:非法小恋_CSDN博客-大数据,SuperMap iServer,Linux领域博主 如发现有错,请留言,谢谢)