标签:lib google raw 用户 rri forward 依赖 启动 通过
版本信息linux Centos7
kubernetes v1.14.5
docker v18.06.1-ce
节点信息
VIP:47.110.19.11 阿里云负载均衡
安装前准备
开始部署前确保所有节点网络正常,能访问公网。主要操作都在VPC-OPEN-MASTER001节点进行,设置VPC-OPEN-MASTER001可以免密码登陆其他节点。所有操作都使用root用户身份进行。
服务器说明
我们这里使用的是五台centos-7.6的虚拟机,具体信息如下表:
系统类型 IP地址 节点角色 CPU Memory Hostname
centos-7.6 192.168.3.42 master >=2 >=4G master01
centos-7.6 192.168.3.43 master >=2 >=4G master02
centos-7.6 192.168.3.44 master >=2 >=4G master03
centos-7.6 192.168.3.45 worker >=2 >=4G node01
centos-7.6 192.168.3.46 worker >=2 >=4G node02
一、环境准备
1、设置主机名
# 查看主机名 $ hostname # 修改主机名 $ hostnamectl set-hostname huoban-k8s-master01 # 配置host,使所有节点之间可以通过hostname互相访问
>2、配置hosts解析
192.168.3.42 huoban-k8s-master01 master01
192.168.3.43 huoban-k8s-master02 master02
192.168.3.44 huoban-k8s-master03 master03
192.168.3.45 huoban-k8s-node01 node01
192.168.3.46 huoban-k8s-node02 node02
>3、安装依赖包
$ yum update
$ yum install -y conntrack ipvsadm ipset jq sysstat curl iptables libseccomp
>4、关闭防火墙、swap,重置iptables
$ systemctl stop firewalld && systemctl disable firewalld
$ iptables -F && iptables -X && iptables -F -t nat && iptables -X -t nat && iptables -P FORWARD ACCEPT
$ swapoff -a
$ sed -i ‘/swap/s/^(.*)$/#\1/g‘ /etc/fstab
$ setenforce 0
$ service dnsmasq stop && systemctl disable dnsmasq
>5、系统参数设置
$ cat > /etc/sysctl.d/kubernetes.conf <<EOF
net.bridge.bridge-nf-call-iptables=1
net.bridge.bridge-nf-call-ip6tables=1
net.ipv4.ip_forward=1
vm.swappiness=0
vm.overcommit_memory=1
vm.panic_on_oom=0
fs.inotify.max_user_watches=89100
EOF
$ sysctl -p /etc/sysctl.d/kubernetes.conf
二、安装docker
wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo
查看可以安装的版本
yum list docker-ce --showduplicates|sort -r
yum install -y docker-ce-18.06.1.ce-3
cat > /etc/docker/daemon.json <<EOF
{
"graph": "/docker/data/path",
"exec-opts": ["native.cgroupdriver=cgroupfs"],
"registry-mirrors":["https://k9e55i4n.mirror.aliyuncs.com"]
}
EOF
systemctl start docker && systemctl enable docker
三、安装 kubeadm, kubelet 和 kubectl
>1、配置yum源
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
>2、安装kubelet,kubeadm,kubectl
yum list kubeadm --showduplicates | sort -r
#安装指定版本
yum install -y kubelet-1.14.5 kubeadm-1.14.5 kubectl-1.14.5
>3、查看安装情况
systemctl cat kubelet
[Unit]
Description=kubelet: The Kubernetes Node Agent
Documentation=http://kubernetes.io/docs/
[Service]
ExecStart=/usr/bin/kubelet
Restart=always
StartLimitInterval=0
RestartSec=10
[Install]
WantedBy=multi-user.target
[Service]
Environment="KUBELET_KUBECONFIG_ARGS=--bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf"
Environment="KUBELET_CONFIG_ARGS=--config=/var/lib/kubelet/config.yaml"
EnvironmentFile=-/var/lib/kubelet/kubeadm-flags.env
EnvironmentFile=-/etc/sysconfig/kubelet
ExecStart=
ExecStart=/usr/bin/kubelet $KUBELET_KUBECONFIG_ARGS $KUBELET_CONFIG_ARGS $KUBELET_KUBEADM_ARGS $KUBELET_EXTRA_ARGS
四、配置系统相关参数
#以下操作在所有节点操作
#!/bin/bash
iptables -P FORWARD ACCEPT
modprobe ip_vs
modprobe ip_vs_rr
modprobe ip_vs_wrr
modprobe ip_vs_sh
modprobe nf_conntrack_ipv4
lsmod | grep ip_vs
五、配置阿里云负载均衡及修改证书
#下载源码包
cd /usr/local/src/
git clone https://github.com/kubernetes/kubernetes.git
git checkout -b kubernetes-1.14.5 origin/release-1.14
#docker拉取修改镜像,对应的版本有1.11.5、1.12.3、1.13.0、1.13.2、1.13.4
docker pull icyboy/k8s_build:v1.14.1
#k8s-1.14以上修改有效期的两个文件,找到NotAfter字段并修改日期有效期
/usr/local/src/kubernetes/staging/src/k8s.io/client-go/util/cert/cert.go
NotAfter: now.Add(duration365d 100).UTC(),
/usr/local/src/kubernetes/cmd/kubeadm/app/util/pkiutil/pki_helpers.go
NotAfter: time.Now().Add(duration365d 100).UTC(), #改成100年
#执行编译
docker run --rm -v /usr/local/src/kubernetes:/go/src/k8s.io/kubernetes -it icyboy/k8s_build:v1.14.1 bash
make all WHAT=cmd/kubeadm GOFLAGS=-v
make all WHAT=cmd/kubelet GOFLAGS=-v
make all WHAT=cmd/kubectl GOFLAGS=-v
#编译完产物在 /usr/local/src/kubernetes/_output/local/bin/linux/amd64 目录下
#将kubeadm 文件拷贝出来,替换系统中的kubeadm
#用新的kubeadm 替换官方的kubeadm
chmod +x kubeadm && \cp -f kubeadm /usr/bin
六、部署第一个主节点
>1、配置kubelet
systemctl daemon-reload
systemctl enable kubelet
>2、根据配置文件初始化集群
LOAD_BALANCER_DNS="47.110.19.11"
LOAD_BALANCER_PORT="6443"
cat > kubeadm-master.config <<EOF
apiVersion: kubeadm.k8s.io/v1beta1
kind: ClusterConfiguration
kubernetesVersion: v1.14.5
imageRepository: registry.cn-hangzhou.aliyuncs.com/google_containers
apiServer:
certSANs:
networking:
podSubnet: 10.244.0.0/16
EOF
#初始化k8s集群
kubeadm init --config=kubeadm-master.config
>3、验证证书有效时间
notBefore=Aug 20 07:43:46 2019 GMT
notAfter=Jul 27 07:43:46 2119 GMT
notBefore=Aug 20 07:43:45 2019 GMT
notAfter=Jul 27 07:43:45 2119 GMT
notBefore=Aug 20 07:43:46 2019 GMT
notAfter=Jul 27 07:43:47 2119 GMT
notBefore=Aug 20 07:43:46 2019 GMT
notAfter=Jul 27 07:43:47 2119 GMT
notBefore=Aug 20 07:43:46 2019 GMT
notAfter=Jul 27 07:43:47 2119 GMT
notBefore=Aug 20 07:43:46 2019 GMT
notAfter=Jul 27 07:43:46 2119 GMT
notBefore=Aug 20 07:43:45 2019 GMT
notAfter=Jul 27 07:43:46 2119 GMT
notBefore=Aug 20 07:43:45 2019 GMT
notAfter=Jul 27 07:43:45 2119 GMT
notBefore=Aug 20 07:43:45 2019 GMT
notAfter=Jul 27 07:43:45 2119 GMT
notBefore=Aug 20 07:43:45 2019 GMT
notAfter=Jul 27 07:43:45 2119 GMT
>4、安装网络插件
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
>5、拷贝master证书到其他节点
USER=root
CONTROL_PLANE_IPS="192.168.3.43 192.168.3.44"
for host in ${CONTROL_PLANE_IPS}; do
scp /etc/kubernetes/pki/ca.crt "${USER}"@$host:
scp /etc/kubernetes/pki/ca.key "${USER}"@$host:
scp /etc/kubernetes/pki/sa.key "${USER}"@$host:
scp /etc/kubernetes/pki/sa.pub "${USER}"@$host:
scp /etc/kubernetes/pki/front-proxy-ca.crt "${USER}"@$host:
scp /etc/kubernetes/pki/front-proxy-ca.key "${USER}"@$host:
scp /etc/kubernetes/pki/etcd/ca.crt "${USER}"@$host:etcd-ca.crt
scp /etc/kubernetes/pki/etcd/ca.key "${USER}"@$host:etcd-ca.key
scp /etc/kubernetes/admin.conf "${USER}"@$host:
ssh ${USER}@${host} ‘mkdir -p /etc/kubernetes/pki/etcd‘
ssh ${USER}@${host} ‘mv /${USER}/ca.crt /etc/kubernetes/pki/‘
ssh ${USER}@${host} ‘mv /${USER}/ca.key /etc/kubernetes/pki/‘
ssh ${USER}@${host} ‘mv /${USER}/sa.pub /etc/kubernetes/pki/‘
ssh ${USER}@${host} ‘mv /${USER}/sa.key /etc/kubernetes/pki/‘
ssh ${USER}@${host} ‘mv /${USER}/front-proxy-ca.crt /etc/kubernetes/pki/‘
ssh ${USER}@${host} ‘mv /${USER}/front-proxy-ca.key /etc/kubernetes/pki/‘
ssh ${USER}@${host} ‘mv /${USER}/etcd-ca.crt /etc/kubernetes/pki/etcd/ca.crt‘
ssh ${USER}@${host} ‘mv /${USER}/etcd-ca.key /etc/kubernetes/pki/etcd/ca.key‘
ssh ${USER}@${host} ‘mv /${USER}/admin.conf /etc/kubernetes/admin.conf‘
done
七、其他节点上部署
#master
kubeadm join 47.110.19.11:6443 --token qlrq5y.1yhm3rz9r7ynfqf1 --discovery-token-ca-cert-hash sha256:62579157003c3537deb44b30f652c500e7fa6505b5ef6826d796ba1245283899 --experimental-control-plane
#node
kubeadm join 47.110.19.11:6443 --token qlrq5y.1yhm3rz9r7ynfqf1 --discovery-token-ca-cert-hash sha256:62579157003c3537deb44b30f652c500e7fa6505b5ef6826d796ba1245283899
Kubernetes系列之kubeadm部署多节点master集群
标签:lib google raw 用户 rri forward 依赖 启动 通过
原文地址:https://blog.51cto.com/79076431/2474350