Debian安装kubernetes1.23.1实战【详细步骤】
大佬文章
路线规划哪家强 文章作者
首先节点全部安装docker
docker -v
安装 kubeadmin 等工具(所有节点)
1、配置安装源
apt-get update && apt-get install -y apt-transport-https
curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add -
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
EOF
apt-get update
2、安装
sudo apt-get install kubectl kubeadm kubelet kubernetes-cni -y
swap off(所有节点)
1、使用free -h 确认没有使用swap
2、如果swap部分不为0, 则使用命令swapoff -a关闭
准备镜像(所有节点)
因为等会的kubeadmin会有超时检查,可以先把镜像下载好。由于国内无法访问k8s.gcr.io仓库,所以必须增加–image-repository 指定国内的镜像仓库。
kubeadm config images pull --image-repository registry.aliyuncs.com/google_containers
disable cgroups(所有节点)
1、修改daemon.json
sudo vim /etc/docker/daemon.json
{
"exec-opts": ["native.cgroupdriver=systemd"]
}
2、重启docker
systemctl daemon-reload
systemctl restart docker
kubeadmin init (master节点)
因为本例采用flannel作为网络插件,所以必须添加子网信息。如果已经把镜像都准备好了,可以不用管–image-repository参数。
以上办法安装报错,可能是我一开始没有给够内存导致失败
一、系统环境
采用最新大佬文章
坐公交也用券 csdn大佬用户
cat /etc/os-release
配置互相解析,主机名称
vim /etc/hosts
vim /etc/hostname
配置能访问外网
cat /etc/resolv.conf
处理器最少2个以上-注意事项:master节点CPU核心最低要求2个
二、配置源
2.1、配置系统源
2.1.1、备份并查看源配置文件
备份源文件
cp /etc/apt/sources.list /etc/apt/sources.list.bak
查看源配置
cat /etc/apt/sources.list #查看原配置文件
2.1.2、更改源地址
此时的配置实际上是我已经改了的,原来的镜像站点地址是debian官网,安装服务的时候比较慢,下面附上替换源的方法。
源配置文件有用的信息主要是下面这些
deb http://mirrors.huaweicloud.com/debian/ buster main
deb-src http://mirrors.huaweicloud.com/debian/ buster main
deb http://security.debian.org/debian-security buster/updates main
deb-src http://security.debian.org/debian-security buster/updates main
deb http://mirrors.huaweicloud.com/debian/ buster-updates main
deb-src http://mirrors.huaweicloud.com/debian/ buster-updates main
源站选择
我们能做的只有URL的替换,其他参数不要改,国内比较好用的源加速站点有:
1、阿里源
2、清华源
3、腾讯源
4、华为源(ARM资源比较多)
5、网易源
因为当前已经是华为源了,所以下面就以比较常用的阿里源进行更换。
https://developer.aliyun.com/mirror/debian #打开这个网址
提取这个mirrors地址,把华为的换成阿里的mirrors,在替换之前,先测试当前源是否可以用
我这边是直接报错的,下面直接替换所有的源为阿里源
rm -f /etc/apt/sources.list #删除源配置文件
echo 'deb http://mirrors.aliyun.com/debian/ buster main
deb-src http://mirrors.aliyun.com/debian/ buster main
deb http://mirrors.aliyun.com/debian-security buster/updates main
deb-src http://mirrors.aliyun.com/debian-security buster/updates main
deb http://mirrors.aliyun.com/debian/ buster-updates main
deb-src http://mirrors.aliyun.com/debian/ buster-updates main
' > /etc/apt/sources.list
更新源配置
apt-get update
2.2、添加Docker源
这里可以直接采用我之前的文章安装docker
2.2.1、写入源文件
Sources_URL='https://mirrors.aliyun.com';echo -e "# deb-src [arch=amd64] ${Sources_URL}/docker-ce/linux/debian buster stable\ndeb [arch=amd64] ${Sources_URL}/docker-ce/linux/debian buster stable\n# deb-src [arch=amd64] ${Sources_URL}/docker-ce/linux/debian buster stable" > /etc/apt/sources.list.d/docker.list
cat /etc/apt/sources.list.d/docker.list #查看源配置参数
2.2.2、更新源列表
apt update
此时遇到错误,提示没有公钥,解决办法有两个:
首先 安装相关系统工具
apt-get install apt-transport-https ca-certificates curl gnupg2 lsb-release software-properties-common -y
第一个方法:
Sources_URL='https://mirrors.aliyun.com'
curl ${Sources_URL}/kubernetes/apt/doc/apt-key.gpg | apt-key add -
第二个方法:
复制下面这个值(这个值好像是随机的)
然后执行语句(也就是把最后一个数值改成没有公钥的数值)
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 7EA0A9C3F273FCD8
反正第一个不行就第二个。 添加完成之后,再次更新源列表
此时,Docker源已经配置成功了。
2.3、配置K8S源
通过docker源的配置,那么K8S的源配置就不多说了。
2.3.1、写入源
echo -e "deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main" > /etc/apt/sources.list.d/kubernetes.list
2.3.2、更新源
到这里,源配置就完成了。
三、系统环境配置
3.1、配置内核转发
写入转发配置参数
echo -e "net.bridge.bridge-nf-call-ip6tables = 1\nnet.bridge.bridge-nf-call-iptables = 1\nnet.ipv4.ip_forward = 1" > /etc/sysctl.conf
应用转发配置
sysctl --system
3.2、主机名修改
本节点的规划是Master节点,所以在这里我的主机名就命名为master,我上面已经配置啦
hostnamectl set-hostname master
3.3、关闭swap
swapoff -a #临时关闭
sed -i '/ swap / s/^\(.*\)$/#/g' /etc/fstab #永久
四、服务安装
4.1、安装Docker
apt-get install -y docker-ce
安装完成之后,启动服务,查看docker版本信息
systemctl restart docker
docker info
docker -v
4.2、安装kubelet组件(K8S)
apt-get install -y kubelet kubeadm kubectl
在master节点操作
启动K8S服务并查看版本信息
systemctl start kubelet
kubeadm version
到这里,服务就安装完成了。
五、配置服务
5.1、配置Docker
5.1.1、配置Docker镜像加速地址及驱动
echo -e "{\n\t\"exec-opts\": [\"native.cgroupdriver=systemd\"],\n\t\"registry-mirrors\": [\"http://hub-mirror.c.163.com\"]\n}" > /etc/docker/daemon.json
我这里是三个docker都配置拉镜像加速
cat /etc/docker/daemon.json
5.1.2、验证镜像加速
systemctl daemon-reload
systemctl restart docker
docker info
5.2、初始化K8S
5.2.1、设置HOSTS映射
首先查看本机IP地址信息-在k8s-master节点
写入映射参数–可以省略
echo '10.1.1.6 master' >> /etc/hosts
查看映射表
cat /etc/hosts
5.2.2、初始化master节点
获取K8S版本
ver=`kubeadm version|awk '{print }'|sed "s/[^0-9|\.]//g"|awk 'NR==1{print}'`
获取本机IP地址
ip=`cat /etc/hosts|grep master|awk '{print }'|awk 'NR==1{print}'`
验证信息
echo -e "k8s version is v${ver}\nmaster ip is ${ip}"
初始化master节点
echo 1 > /proc/sys/net/bridge/bridge-nf-call-iptables
kubeadm init --apiserver-advertise-address=${ip} \
--image-repository registry.aliyuncs.com/google_containers \
--kubernetes-version v${ver} \
--service-cidr=10.1.0.0/16 \
--pod-network-cidr=10.244.0.0/16
如果CPU数量不足,会提示错误,无法初始化
解决办法:加配置或者放弃
增加CPU核心之后,需要重启虚拟机
重启之后,查看CPU信息
cat /proc/cpuinfo
我这里的报错
问题
[ERROR CRI]: runtime is not running: output: E0704 15:55:13.285883 7777 remote_runtime.go:925] "Status from runtime service failed" err="rpc error: code = Unimplemented desc = unknown service runtime.v1alpha2.RuntimeService"
time="2022-07-04T15:55:13+08:00" level=fatal msg="getting status of runtime: rpc error: code = Unimplemented desc = unknown service runtime.v1alpha2.RuntimeService"
, error: exit status 1
解决办法:
首先,确认安装的kubenetes版本和初始化的版本是否一直。
如果一致执行下面的命令,进行修复。
[root@k8s-master:~] rm -rf /etc/containerd/config.toml
[root@k8s-master:~] systemctl restartd
输入后再次执行kubeadm init,正常运行。
kubernetes集群初始化kubeadm启动失败
问题
[wait-control-plane] Waiting for the kubelet to boot up the control plane as static Pods from directory "/etc/kubernetes/manifests". This can take up to 4m0s
[kubelet-check] Initial timeout of 40s passed.
Unfortunately, an error has occurred:
timed out waiting for the condition
This error is likely caused by:
- The kubelet is not running
- The kubelet is unhealthy due to a misconfiguration of the node in some way (required cgroups disabled)
If you are on a systemd-powered system, you can try to troubleshoot the error with the following commands:
- 'systemctl status kubelet'
- 'journalctl -xeu kubelet'
Additionally, a control plane component may have crashed or exited when started by the runtime.
To troubleshoot, list alls using your preferred runtimes CLI.
Here is one example how you may list all Kubernetess running in docker:
- 'docker ps -a | grep kube | grep -v pause'
Once you have found the failing, you can inspect its logs with:
- 'docker logs CONTAINERID'
error execution phase wait-control-plane: couldn't initialize a Kubernetes cluster
To see the stack trace of this error execute with --v=5 or higher
报错提示我使用journalctl -xeu kubelet
查看日志,我们打印日志,结果如下
这里面有两种报错,我跟据这些报错都查了一遍
node “k8s-master” not found:这是中间错误,查他没用,他不是根源
Failed to initialize CSINodeInfo,dial tcp ip:6443: connect: connection refused:这个错误是初始化失败
报错2:error execution phase preflight: [preflight] Some fatal errors occurred: [ER
过程回顾:
[root@test2 ~]# kubeadm init --apiserver-advertise-address=192.168.2.129 --image-repository registry.aliyuncs.com/google_containers --kubernetes-version v1.13.3 --service-cidr=10.1.0.0/16 --pod-network-cidr=10.244.0.0/16
[init] Using Kubernetes version: v1.13.3
[preflight] Running pre-flight checks
error execution phase preflight: [preflight] Some fatal errors occurred:
[ERROR Port-6443]: Port 6443 is in use
[ERROR Port-10251]: Port 10251 is in use
[ERROR Port-10252]: Port 10252 is in use
[ERROR FileAvailable--etc-kubernetes-manifests-kube-apiserver.yaml]: /etc/kubernetes/manifests/kube-apiserver.yaml already exists
[ERROR FileAvailable--etc-kubernetes-manifests-kube-controller-manager.yaml]: /etc/kubernetes/manifests/kube-controller-manager.yaml already exists
[ERROR FileAvailable--etc-kubernetes-manifests-kube-scheduler.yaml]: /etc/kubernetes/manifests/kube-scheduler.yaml already exists
[ERROR FileAvailable--etc-kubernetes-manifests-etcd.yaml]: /etc/kubernetes/manifests/etcd.yaml already exists
[ERROR Port-10250]: Port 10250 is in use
[ERROR Port-2379]: Port 2379 is in use
[ERROR Port-2380]: Port 2380 is in use
[ERROR DirAvailable--var-lib-etcd]: /var/lib/etcd is not empty
[preflight] If you know what you are doing, you can make a check non-fatal with `--ignore-preflight-errors=...
问题解决:
[root@test2 ~]# kubeadm reset //重启kubeadm
[reset] WARNING: changes made to this host by 'kubeadm init' or 'kubeadm join' will be reverted.
[reset] are you sure you want to proceed? [y/N]: y //输入y
[preflight] running pre-flight checks
[reset] Reading configuration from the cluster...
[reset] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -oyaml'
W0717 17:33:41.676764 77512 reset.go:213] [reset] Unable to fetch the kubeadm-config ConfigMap, using etcd pod spec as fallback: failed to get config map: configmaps "kubeadm-config" not found
[reset] stopping the kubelet service
[reset] unmounting mounted directories in "/var/lib/kubelet"
[reset] deleting contents of stateful directories: [/var/lib/etcd /var/lib/kubelet /etc/cni/net.d /var/lib/dockershim /var/run/kubernetes]
[reset] deleting contents of config directories: [/etc/kubernetes/manifests /etc/kubernetes/pki]
[reset] deleting files: [/etc/kubernetes/admin.conf /etc/kubernetes/kubelet.conf /etc/kubernetes/bootstrap-kubelet.conf /etc/kubernetes/controller-manager.conf /etc/kubernetes/scheduler.conf]
The reset process does not reset or clean up iptables rules or IPVS tables.
If you wish to reset iptables, you must do so manually.
For example:
iptables -F && iptables -t nat -F && iptables -t mangle -F && iptables -X
If your cluster was setup to utilize IPVS, run ipvsadm --clear (or similar)
to reset your system's IPVS tables.
[root@test2 ~]# kubeadm init \
--apiserver-advertise-address=192.168.2.129 \
--image-repository registry.aliyuncs.com/google_containers \
--kubernetes-version v1.13.3 \
--service-cidr=10.1.0.0/16 \
--pod-network-cidr=10.244.0.0/16
......
Your Kubernetes master 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/
You can now join any number of machines by running the following on each node
as root:
kubeadm join 192.168.2.129:6443 --token si974n.v8615659h9x6x4xe --discovery-token-ca-cert-hash sha256:d6d1c5d0290ee0217d14d7d6bdea23b1fc911186e0ea94847a1f52d8ed32761d
我是用的这个方法解决
https://blog.csdn.net/curry10086/article/details/107579113?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522165787880516782246429231%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=165787880516782246429231&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduend~default-1-107579113-null-null.142^v32^pc_search_result_control_group,185^v2^control&utm_term=kubelet-check%5D%20Initial%20timeout%20of%2040s%20passed.&spm=1018.2226.3001.4187
查看需要的版本
https://www.toutiao.com/article/6910033246273552903/?wid=1658057154985
我们可以使用下面的命令获取基础镜像的列表:
kubeadm config images list
k8s是node节点运行容器,每个节点都要先去拉取镜像
# cat dockerPull.sh
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.24.3
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.24.3
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.24.3
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.24.3
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.8.6
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.5.3-0
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.7
修改Tar
# cat dockerTar.sh
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.24.3 k8s.gcr.io/kube-controller-manager:v1.24.3
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.24.3 k8s.gcr.io/kube-proxy:v1.24.3
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.24.3 k8s.gcr.io/kube-apiserver:v1.24.3
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.24.3 k8s.gcr.io/kube-scheduler:v1.24.3
#docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.8.4 k8s.gcr.io/coredns:1.8.4
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.8.6 k8s.gcr.io/coredns/coredns:v1.8.6
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.5.3-0 k8s.gcr.io/etcd:3.5.3-0
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.7 k8s.gcr.io/pause:3.7
以上问题没有解决,选择更换安装文档 ,最终解决方法, 更换版本在下面第二种方法里面使用的,可以直接参考下面的解决文档
Debian10使用kubeadm搭建k8s集群—
大佬文章
https://www.yuque.com/yanfei.wu/rxdf4h/grso12
一、环境规划
1、集群类型
- 一主两从:一台Master节点和两台Node节点
2、安装方式
- kubeadm: kubernetes.io 官方推荐的工具,便于快速安装 kubernetes 集群
3、主机规划
主机名 | IP地址 | 操作系统 | 配置 |
Master | 196.196.196.11 | Debian 10.10 | 4核CPU 3G内存 20G硬盘 |
Node1 | 196.196.196.22 | Debian 10.10 | 4核CPU 2G内存 20G硬盘 |
Node2 | 196.196.196.33 | Debian 10.10 | 4核CPU 2G内存 20G硬盘 |
4、软件版本
Docker version:19.03.8
Kubernetes version :1.21.2
- k8s.gcr.io/kube-apiserver:v1.21.2k8s.gcr.io/kube-controller-manager:v1.21.2
- k8s.gcr.io/kube-scheduler:v1.21.2
- k8s.gcr.io/kube-proxy:v1.21.2
- k8s.gcr.io/pause:3.4.1
- k8s.gcr.io/etcd:3.4.13-0
- k8s.gcr.io/coredns/coredns:v1.8.0
- flannel: v0.14.0
二、环境初始化
1、主机名解析
编辑三台服务器的/etc/hosts
文件,添加下面内容
196.196.196.11 k8s-master
196.196.196.22 k8s-node1
196.196.196.33 k8s-node2
配置能访问外网
2、时间同步
ntpdate ntp.aliyun.com
echo "203.107.6.88 root ntpdate ntp.aliyun.com" >> /etc/crontab
3、禁用swap分区
swapoff -a
sed -ri 's/.*swap.*/#&/' /etc/fstab
4、linux的内核参数配置
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
br_netfilter
EOF
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sudo sysctl --system
5、安装docker
apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
gnupg2 \
software-properties-common
curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/debian/gpg | sudo apt-key add -
apt-key fingerprint 0EBFCD88
add-apt-repository \
"deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/debian \
$(lsb_release -cs) \
stable"
apt-get update
apt-get install docker-ce=5:19.03.8~3-0~debian-buster docker-ce-cli=5:19.03.8~3-0~debian-busterd.io -y
安装docker参考菜鸟教程:
也可以参考我的文章
https://www.runoob.com/docker/debian-docker-install.html
Docker在默认情况下使用的Cgroup Driver为cgroupfs,而kubernetes推荐使用systemd来代替cgroupfs
vim /etc/docker/daemon.json
{
"exec-opts": ["native.cgroupdriver=systemd"],
"registry-mirrors": ["https://kn0t2bca.mirror.aliyuncs.com"]
}
重启docker
systemctl daemon-reload
systemctl restart docker
systemctl enable docker
6、安装k8s组件
安装kubelet kubeadm kubectl,先配置国内源,再进行安装。
apt-get update && apt-get install -y apt-transport-https curl
curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add -
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
EOF
apt-get update
apt-get install -y kubelet kubeadm kubectl #安装最新版本--可能不适配
apt-get install -y kubelet=1.23.6-00 kubeadm=1.23.6-00 kubectl=1.23.6-00 ##安装指定版本 v1.23.9
apt-mark hold kubelet kubeadm kubectl #设置不随系统更新而更新
7、拉取集群所需镜像
在安装kubernetes集群之前,必须要提前准备好集群需要的镜像,所需镜像可以通过下面命令查看
kubeadm config images list
下载镜像
此镜像在kubernetes的仓库中,由于网络原因,无法连接,可以先从阿里仓库进行pull,再tag打标签。
定义镜像
images=(
kube-apiserver:v1.23.9
kube-controller-manager:v1.23.9
kube-scheduler:v1.23.9
kube-proxy:v1.23.9
pause:3.7
etcd:3.5.3-0
coredns/coredns:v1.8.6
)
我这里是拉取v1.24.3
拉取镜像
for imageName in ${images[@]} ; do
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/$imageName
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/$imageName k8s.gcr.io/$imageName
docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/$imageName
done
coredns/coredns:v1.8.0 镜像应该拉取不到,因为在阿里仓库 其名称为coredns:1.8.0,可以先手动拉取再打标签修改名称
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.8.0
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.8.0 k8s.gcr.io/coredns/coredns:v1.8.0
查看所有节点
三、集群初始化
*下面的操作只需要在****master节点\***
*上执行*
创建集群
[root@master ~]# kubeadm init \
--kubernetes-version=v1.24.3 \
--pod-network-cidr=10.244.0.0/16 \
--service-cidr=10.96.0.0/12 \
--apiserver-advertise-address=196.196.196.11
初始化报错
查看相关日志
systemctl status kubelet
解决方法:
我问了下我老师,也查了下资料k8s 已经弃用了docker了,如果安装的kubelet kubeadm kubectl
是V1.24就会出现以上错误,安装的时候指定一下1.23版本,就可以解决了:yum install -y kubelet-1.23.6 kubeadm-1.23.6 kubectl-1.23.6
————————————————
查看相关版本
最终解决方法,更换 v1.23.9
安装指定版本
apt-get install -y kubelet=1.23.6-00 kubeadm=1.23.6-00 kubectl=1.23.6-00 ##安装指定版本 v1.23.9
拉取镜像
cat dockerpull.sh
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.23.9
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.23.9
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.23.9
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.23.9
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.8.6
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.5.1-0
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.6
修改tar
cat dockerTar.sh
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.23.9 k8s.gcr.io/kube-controller-manager:v1.23.9
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.23.9 k8s.gcr.io/kube-proxy:v1.23.9
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.23.9 k8s.gcr.io/kube-apiserver:v1.23.9
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.23.9 k8s.gcr.io/kube-scheduler:v1.23.9
#docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.8.4 k8s.gcr.io/coredns:1.8.4
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.8.6 k8s.gcr.io/coredns/coredns:v1.8.6
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.5.1-0 k8s.gcr.io/etcd:3.5.1-0
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.6 k8s.gcr.io/pause:3.6
创建集群*只需要在****master节点\***
*上执行*
kubeadm init \
--kubernetes-version=v1.23.9 \
--pod-network-cidr=10.244.0.0/16 \
--service-cidr=10.96.0.0/12 \
--apiserver-advertise-address=196.196.196.11
初始化完成-这个TOken保存好
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 196.196.196.11:6443 --token lpjexj.mbh1l4vd8ulkjxh0 \
--discovery-token-ca-cert-hash sha256:a17480589d439792e7afaacc83abb877243b2d0dbb915d08373f8618e74240a2
创建必要文件
[root@master ~]# mkdir -p $HOME/.kube
[root@master ~]# sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
[root@master ~]# sudo chown $(id -u):$(id -g) $HOME/.kube/config
查看node节点
[root@k8s-master ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s-master NotReady master 2m41s v1.23.6
下面的操作只需要在******node节点\***
***上执行\
复制上面token
kubeadm join 196.196.196.11:6443 --token lpjexj.mbh1l4vd8ulkjxh0 \
--discovery-token-ca-cert-hash sha256:a17480589d439792e7afaacc83abb877243b2d0dbb915d08373f8618e74240a2
四、安装网络插件
kubernetes支持多种网络插件,比如flannel、calico、canal等等,任选一种使用即可,本次选择flannel
下面操作依旧只在master节点执行即可*,插件使用的是DaemonSet的控制器,它会在每个节点上都运行*
wget https://kuboard.cn/install-script/flannel/flannel-v0.14.0.yaml
kubectl apply -f flannel-v0.14.0.yaml
稍等片刻,再次查看集群节点的状态
[root@master ~]# kubectl get node
NAME STATUS ROLES AGE VERSION
master Ready control-plane,master 6m29s v1.23.6
node1 Ready <none> 2m47s v1.23.6
node2 Ready <none> 2m38s v1.23.6
至此,kubernetes的集群环境搭建完成
get nodes
NAME STATUS ROLES AGE VERSION
k8s-master NotReady master 2m41s v1.23.6
[外链图片转存中...(img-yEtHHpPr-1658197153142)]
###### 下面的操作只需要在\***`***node节点\***`***上执行\
复制上面token
```shell
kubeadm join 196.196.196.11:6443 --token lpjexj.mbh1l4vd8ulkjxh0 \
--discovery-token-ca-cert-hash sha256:a17480589d439792e7afaacc83abb877243b2d0dbb915d08373f8618e74240a2
[外链图片转存中…(img-DLNdOkgn-1658197153142)]
四、安装网络插件
kubernetes支持多种网络插件,比如flannel、calico、canal等等,任选一种使用即可,本次选择flannel
下面操作依旧只在master节点执行即可*,插件使用的是DaemonSet的控制器,它会在每个节点上都运行*
wget https://kuboard.cn/install-script/flannel/flannel-v0.14.0.yaml
kubectl apply -f flannel-v0.14.0.yaml
稍等片刻,再次查看集群节点的状态
[root@master ~]# kubectl get node
NAME STATUS ROLES AGE VERSION
master Ready control-plane,master 6m29s v1.23.6
node1 Ready <none> 2m47s v1.23.6
node2 Ready <none> 2m38s v1.23.6
至此,kubernetes的集群环境搭建完成