成都建设网官方网站,百度查询入口,一个网站开发背景是什么,容桂网站制作值得信赖集群部署 1、kubeadm流程#xff08;重新配置#xff09;1.1 安装要求1.2 准备环境 1.3. 所有节点安装Docker/kubeadm/kubelet1.3.1 安装Docker1.3.2 添加阿里云YUM软件源1.3.3 安装kubeadm#xff0c;kubelet和kubectl 1.4 部署Kubernetes Master1.5. 加入Kubernetes Node1… 集群部署 1、kubeadm流程重新配置1.1 安装要求1.2 准备环境 1.3. 所有节点安装Docker/kubeadm/kubelet1.3.1 安装Docker1.3.2 添加阿里云YUM软件源1.3.3 安装kubeadmkubelet和kubectl 1.4 部署Kubernetes Master1.5. 加入Kubernetes Node1.6. 部署CNI网络插件(也可以参考之前的学习内容)1.7. 测试kubernetes集群1.8 错误处理1.9 配置kubectl命令补齐功能 1、kubeadm流程重新配置
1.1 安装要求
三台机器centos7.6禁用swap分区机器间网络互通能ping通外网2核、2CPU、硬盘20G → 最低配置。
1.2 准备环境
# 关闭防火墙
systemctl stop firewalld
systemctl disable firewalld# 关闭selinux
sed -i s/enforcing/disabled/ /etc/selinux/config # 永久
setenforce 0 # 临时# 关闭swap
swapoff -a # 临时
sed -ri s/.*swap.*/#/ /etc/fstab # 永久# 根据规划设置主机名
hostnamectl set-hostname hostname# 在master添加hosts
cat /etc/hosts EOF
192.168.44.146 k8smaster
192.168.44.145 k8snode1
192.168.44.144 k8snode2
EOF# 将桥接的IPv4流量传递到iptables的链
cat /etc/sysctl.d/k8s.conf EOF
net.bridge.bridge-nf-call-ip6tables 1
net.bridge.bridge-nf-call-iptables 1
EOF
sysctl --system # 生效
#不设置可能出现下述问题
bash
rootlocalhost ~]# kubeadm init --configkubeadm.yaml
W1214 16:08:06.965502 47724 strict.go:55] error unmarshaling configuration schema.GroupVersionKind{Group:kubeadm.k8s.io, Version:v1beta3, Kind:ClusterConfiguration}: error unmarshaling JSON: while decoding JSON: json: unknown field apiServerExtraArgs
[init] Using Kubernetes version: v1.23.0
[preflight] Running pre-flight checks
error execution phase preflight: [preflight] Some fatal errors occurred:[ERROR FileContent--proc-sys-net-bridge-bridge-nf-call-iptables]: /proc/sys/net/bridge/bridge-nf-call-iptables contents are not set to 1[ERROR FileContent--proc-sys-net-ipv4-ip_forward]: /proc/sys/net/ipv4/ip_forward contents are not set to 1
[preflight] If you know what you are doing, you can make a check non-fatal with --ignore-preflight-errors...
To see the stack trace of this error execute with --v5 or higher#可以通过kubeadm reset重置进行操作。
#上面错误未将设置为1 解决如下
[rootlocalhost ~]# echo 1 /proc/sys/net/bridge/bridge-nf-call-iptables
[rootlocalhost ~]# echo 1 /proc/sys/net/ipv4/ip_forward# 时间同步
yum install ntpdate -y
ntpdate time.windows.com1.3. 所有节点安装Docker/kubeadm/kubelet
Kubernetes默认CRI容器运行时为Docker因此先安装Docker。
1.3.1 安装Docker
$ wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo
$ yum -y install docker-ce-20.10.12.ce-3.el7
$ systemctl enable docker systemctl start docker
$ docker --version
Docker version 18.06.1-ce, build e68fc7a
$ docker info Registry Mirrors:https://8agoeabf.mirror.aliyuncs.com/# 配置阿里云加速器
$ cat /etc/docker/daemon.json EOF
{registry-mirrors: [https://b9pmyelo.mirror.aliyuncs.com]
}
EOF1.3.2 添加阿里云YUM软件源
$ cat /etc/yum.repos.d/kubernetes.repo EOF
[kubernetes]
nameKubernetes
baseurlhttps://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled1
gpgcheck0
repo_gpgcheck0
gpgkeyhttps://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF1.3.3 安装kubeadmkubelet和kubectl
由于版本更新频繁这里指定版本号部署
$ yum install -y kubelet-1.20.0 kubeadm-1.20.0 kubectl-1.20.0
$ systemctl enable kubelet1.4 部署Kubernetes Master
在192.168.31.61Master执行。
$ kubeadm init \--apiserver-advertise-address192.168.44.146 \--image-repository registry.aliyuncs.com/google_containers \--kubernetes-version v1.18.0 \--service-cidr10.96.0.0/12 \--pod-network-cidr10.244.0.0/16由于默认拉取镜像地址k8s.gcr.io国内无法访问这里指定阿里云镜像仓库地址。
使用kubectl工具
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
$ kubectl get nodes1.5. 加入Kubernetes Node
在192.168.1.12/13Node执行。
向集群添加新节点执行在kubeadm init输出的kubeadm join命令
$ kubeadm join 192.168.1.11:6443 --token esce21.q6hetwm8si29qxwn \--discovery-token-ca-cert-hash sha256:00603a05805807501d7181c3d60b478788408cfe6cedefedb1f97569708be9c5默认token有效期为24小时当过期之后该token就不可用了。这时就需要重新创建tokenmaster操作如下
kubeadm token create --print-join-command1.6. 部署CNI网络插件(也可以参考之前的学习内容)
wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml默认镜像地址无法访问sed命令修改为docker hub镜像仓库或者直接网页打开网址复制到centos中的新建yaml文件中。
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.ymlkubectl get pods -n kube-system
NAME READY STATUS RESTARTS AGE
kube-flannel-ds-amd64-2pc95 1/1 Running 0 72s1.7. 测试kubernetes集群
在Kubernetes集群中创建一个pod验证是否正常运行
$ kubectl create deployment nginx --imagenginx
$ kubectl expose deployment nginx --port80 --typeNodePort
$ kubectl get pod,svc访问地址http://NodeIP:Port
1.8 错误处理
# 1.如果node节点kubelet服务起不来可以看一下这两个文件夹是否和master一致或者是否有文件。需要传一下master的admin.conf文件
[rootlocalhost kubernetes]# pwd
/etc/kubernetes
[rootlocalhost lib]# pwd
/var/lib1.9 配置kubectl命令补齐功能
echo source (kubectl completion bash) ~/.bashrc