准备工作:https://blog.csdn.net/weixin_40165163/article/details/104526461

kube-proxy开启ipvs的前置条件

yum -y install ipvsadm
modprobe br_netfilter
cat > /etc/sysconfig/modules/ipvs.modules <<EOF
#!/bin/bash
modprobe -- ip_vs
modprobe -- ip_vs_rr
modprobe -- ip_vs_wrr
modprobe -- ip_vs_sh
modprobe -- nf_conntrack_ipv4
EOF
chmod 755 /etc/sysconfig/modules/ipvs.modules && bash /etc/sysconfig/modules/ipvs.modules && lsmod | grep -e ip_vs -e nf_conntrack_ipv4

当centos的环境准备好后,就可以开始部署k8s了

首先设置k8s下载源

cat <<EOF > /etc/yum.repos.d/kubernetes.repo

[kubernetes]

name=Kubernetes

baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64

enabled=1

gpgcheck=0

repo_gpgcheck=0

gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg

        http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg

EOF

 

下载k8s组件(kubelet、kubeadm、kubectl)

yum install -y kubelet kubeadm kubectl

 

启动k8s

systemctl enable kubelet && systemctl start kubelet

 

创建init配置文件

kubeadm config print init-defaults > kubeadm-config.yaml

打印出来 vim
 

apiVersion: kubeadm.k8s.io/v1beta2
bootstrapTokens:
- groups:
  - system:bootstrappers:kubeadm:default-node-token
  token: abcdef.0123456789abcdef
  ttl: 24h0m0s
  usages:
  - signing
  - authentication
kind: InitConfiguration
localAPIEndpoint:
  advertiseAddress: 1.2.3.4
  bindPort: 6443
nodeRegistration:
  criSocket: /var/run/dockershim.sock
  name: k8s-master
  taints:
  - effect: NoSchedule
    key: node-role.kubernetes.io/master
---
apiServer:
  timeoutForControlPlane: 4m0s
apiVersion: kubeadm.k8s.io/v1beta2
certificatesDir: /etc/kubernetes/pki
clusterName: kubernetes
controllerManager: {}
dns:
  type: CoreDNS
etcd:
  local:
    dataDir: /var/lib/etcd
imageRepository: k8s.gcr.io
kind: ClusterConfiguration
kubernetesVersion: v1.17.0
networking:
  dnsDomain: cluster.local
  serviceSubnet: 10.96.0.0/12
scheduler: {}

修改advertiseAddress: 192.168.170.140 为master地址

修改为ipvs模式

apiVersion: kubeproxy.config.k8s.io/v1alpha1
kind: KubeProxyConfiguration
featureGates:
  SupportIPVSProxyMode: true
mode: ipvs

修改后的文件 

apiVersion: kubeadm.k8s.io/v1beta2
bootstrapTokens:
- groups:
  - system:bootstrappers:kubeadm:default-node-token
  token: abcdef.0123456789abcdef
  ttl: 24h0m0s
  usages:
  - signing
  - authentication
kind: InitConfiguration
localAPIEndpoint:
  advertiseAddress: 192.168.170.140
  bindPort: 6443
nodeRegistration:
  criSocket: /var/run/dockershim.sock
  name: k8s-master
  taints:
  - effect: NoSchedule
    key: node-role.kubernetes.io/master
---
apiServer:
  timeoutForControlPlane: 4m0s
apiVersion: kubeadm.k8s.io/v1beta2
certificatesDir: /etc/kubernetes/pki
clusterName: kubernetes
controllerManager: {}
dns:
  type: CoreDNS
etcd:
  local:
    dataDir: /var/lib/etcd
imageRepository: k8s.gcr.io
kind: ClusterConfiguration
kubernetesVersion: v1.17.0
networking:
  dnsDomain: cluster.local
  podSubnet: "10.244.0.0/16"
  serviceSubnet: 10.96.0.0/12

scheduler: {}
---
apiVersion: kubeproxy.config.k8s.io/v1alpha1
kind: KubeProxyConfiguration
featureGates:
  SupportIPVSProxyMode: true
mode: ipvs

 

初始化,需要docker在启动状态: 

kubeadm init --config=kubeadm-config.yaml --upload-certs | tee kubeadm-init.log

遇到的问题:

警告,docker非开机启动根据提示的命令执行一下即可。

[WARNING Service-Docker]: docker service is not enabled, please run 'systemctl enable docker.service'
systemctl enable docker.service

 docker 的驱动程序是cgroupfs推荐设置为systemd

[WARNING IsDockerSystemdCheck]: detected "cgroupfs" as the Docker cgroup driver. The recommended driver is "systemd". Please follow the guide at https://kubernetes.io/docs/setup/cri/ 

 vim /etc/docker/daemon.json

添加下面的配置即可

{"registry-mirrors": ["https://wv1h618x.mirror.aliyuncs.com"],"exec-opts": ["native.cgroupdriver=systemd"],"log-driver": "json-file","log-opts": {"max-size": "100m"}}

重启

systemctl daemon-reload && systemctl restart docker && systemctl enable docker 

启动成功,注意在启动成功的时候下面会有提示信息让我们进行相关的操作,并且进入node的命令也在里面:

如果有些生成的配置被我们改乱掉了也可以重新来过。

kubeadm reset

查看node节点:

发现master 为 notready,查看pod:

查看pod后发现是网络错误,也就是flannel没有安装,我们拉取一下flannel的镜像。

 docker pull quay-mirror.qiniu.com/coreos/flannel:v0.11.0-amd64
  docker tag quay-mirror.qiniu.com/coreos/flannel:v0.11.0-amd64 quay.io/coreos/flannel:v0.11.0-s390x

 之后按照启动成功下面的提示设置一下:

 wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
  sudo kubectl apply -f kube-flannel.yml

 之后删除掉失败的pod节点,它会自动恢复稍等即可:

kubectl delete -n kube-system  pod kube-flannel-ds-amd64-vpwfq

再次查看pod:

查看node:


  至此 master节点部署完毕,接下来我们配置一下其他的node节点,准备工作相同,在node节点我们也将k8s下载好。

之后使用我们在init 时候自动生成的 join命令添加到node中即可:

kubeadm join 192.168.20.65:6443 --token amljc8.492yukyk298pv14a \
    --discovery-token-ca-cert-hash sha256:33afada52a81fdc062f5722801224225ca59e9ef9e1be24ccbd5ee916a479bdc

 查看node我这里部署了两个node:

相同的NotReady这次我们等待即可不需要在每个节点都安装flannel

 

 

 

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐