Centos7.6部署k8s单机环境(v1.16.2)
一、服务器地址规划
ip | hostname | installation |
192.168.1.71 | master1 | kube-apiserver,kube-controller-manager,kube-scheduler,etcd,kube-proxy,flannel |
192.168.1.72 | node1 | kube-proxy,coredns,flannel |
192.168.1.73 | node2 | kube-proxy,coredns,flannel |
二、服务器环境配置(所有服务器执行)
1、安装epel源
yum -y install epel-release
2、安装常用工具
yum -y install vim wget nmap lsof iotop lrzsz ntpdate tree
3、修改服务器时区,时间同步
rm -rf /etc/localtime cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime ntpdate time1.aliyun.com
crontab -e */3 * * * * /usr/sbin/ntpdate time1.aliyun.com >/dev/null 2>&1
4、关闭防火墙、selinux
systemctl disable firewalld.service systemctl stop firewalld.service sed -i ‘s/^SELINUX=.*/SELINUX=disabled/g‘ /etc/selinux/config && setenforce 0
5、关闭swap
swapoff -a sed -i ‘s/^.*swap/#&/g‘ /etc/fstab
6、内核参数优化
cat >> /etc/sysctl.conf << EOF net.ipv4.tcp_keepalive_time = 1200 net.ipv4.ip_local_port_range = 1024 65000 net.ipv4.tcp_max_syn_backlog = 8192 net.ipv4.tcp_max_tw_buckets = 5000 net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_tw_recycle = 1 net.ipv4.tcp_fin_timeout = 30 vm.max_map_count = 262144 fs.file-max = 655350 net.core.somaxconn=20480 net.ipv4.ip_forward = 1 EOF sysctl -p
7、调整文件描述符和进程数量的限制
cat >> /etc/security/limits.conf << EOF * soft nofile 655350 * hard nofile 655350 * soft nproc 655350 * hard nproc 655350 EOF
8、重启服务器
reboot
三、安装docker-ce服务(所有服务器执行)
1、卸载服务器可能已安装的docker环境
yum -y remove docker-ce docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-selinux docker-engine-selinux docker-engine
2、安装docker依赖包
yum -y install yum-utils device-mapper-persistent-data lvm2
3、添加yum源
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
4、安装docker-ce服务
yum -y install --setopt=obsoletes=0 docker-ce systemctl daemon-reload systemctl enable docker systemctl start docker
四、安装kubeadm、kubectl、kubelet(所有服务器执行)
1、添加yum源
cat > /etc/yum.repos.d/kubernetes.repo << EOF [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 EOF
2、卸载服务器上可能已安装的版本
yum -y remove kubelet kubeadm kubectl
3、安装kubeadm、kubectl、kubelet
yum -y install kubelet-1.16.2-0.x86_64 kubeadm-1.16.2-0.x86_64 kubectl-1.16.2-0.x86_64 --disableexcludes=kubernetes systemctl daemon-reload systemctl enable kubelet
4、开启bridge-nf模式
cat >> /etc/sysctl.conf << EOF net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 EOF sysctl -p echo 1 >/proc/sys/net/bridge/bridge-nf-call-iptables echo 1 >/proc/sys/net/bridge/bridge-nf-call-ip6tables
5、开启IP数据包转发功能
echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf sysctl -p
五、准备安装所需的镜像
1、master服务器(master服务器执行)
docker pull gcr.azk8s.cn/google_containers/kube-apiserver:v1.16.2 docker pull gcr.azk8s.cn/google_containers/kube-controller-manager:v1.16.2 docker pull gcr.azk8s.cn/google_containers/kube-scheduler:v1.16.2 docker pull gcr.azk8s.cn/google_containers/kube-proxy:v1.16.2 docker pull gcr.azk8s.cn/google_containers/etcd:3.3.15-0 docker pull gcr.azk8s.cn/google_containers/pause:3.1 docker pull gcr.azk8s.cn/google_containers/coredns:1.6.2 docker pull quay.io/coreos/flannel:v0.11.0-amd64 docker tag gcr.azk8s.cn/google_containers/kube-apiserver:v1.16.2 k8s.gcr.io/kube-apiserver:v1.16.2 docker tag gcr.azk8s.cn/google_containers/kube-controller-manager:v1.16.2 k8s.gcr.io/kube-controller-manager:v1.16.2 docker tag gcr.azk8s.cn/google_containers/kube-scheduler:v1.16.2 k8s.gcr.io/kube-scheduler:v1.16.2 docker tag gcr.azk8s.cn/google_containers/kube-proxy:v1.16.2 k8s.gcr.io/kube-proxy:v1.16.2 docker tag gcr.azk8s.cn/google_containers/etcd:3.3.15-0 k8s.gcr.io/etcd:3.3.15-0 docker tag gcr.azk8s.cn/google_containers/pause:3.1 k8s.gcr.io/pause:3.1 docker tag gcr.azk8s.cn/google_containers/coredns:1.6.2 k8s.gcr.io/coredns:1.6.2 docker rmi gcr.azk8s.cn/google_containers/kube-apiserver:v1.16.2 docker rmi gcr.azk8s.cn/google_containers/kube-controller-manager:v1.16.2 docker rmi gcr.azk8s.cn/google_containers/kube-scheduler:v1.16.2 docker rmi gcr.azk8s.cn/google_containers/kube-proxy:v1.16.2 docker rmi gcr.azk8s.cn/google_containers/etcd:3.3.15-0 docker rmi gcr.azk8s.cn/google_containers/coredns:1.6.2 docker rmi gcr.azk8s.cn/google_containers/pause:3.1
2、node服务器(node服务器执行)
docker pull gcr.azk8s.cn/google_containers/kube-proxy:v1.16.2 docker pull gcr.azk8s.cn/google_containers/pause:3.1 docker pull gcr.azk8s.cn/google_containers/coredns:1.6.2 docker pull quay.io/coreos/flannel:v0.11.0-amd64 docker tag gcr.azk8s.cn/google_containers/kube-proxy:v1.16.2 k8s.gcr.io/kube-proxy:v1.16.2 docker tag gcr.azk8s.cn/google_containers/pause:3.1 k8s.gcr.io/pause:3.1 docker tag gcr.azk8s.cn/google_containers/coredns:1.6.2 k8s.gcr.io/coredns:1.6.2 docker rmi gcr.azk8s.cn/google_containers/kube-proxy:v1.16.2 docker rmi gcr.azk8s.cn/google_containers/coredns:1.6.2 docker rmi gcr.azk8s.cn/google_containers/pause:3.1
六、初始化安装集群服务
1、创建master初始化配置文件(master服务器执行)
[ ! -d /etc/kubernetes/yaml ] && mkdir -p /etc/kubernetes/yaml cat > /etc/kubernetes/yaml/kubeadm-config.yaml << EOF apiVersion: kubeadm.k8s.io/v1beta1 kind: ClusterConfiguration kubernetesVersion: v1.16.2 apiServer: certSANs: - "192.168.0.71" controlPlaneEndpoint: "192.168.0.71:6443" networking: podSubnet: 10.244.0.0/16
EOF
2、初始化安装master(master服务器执行)
kubeadm init --config=/etc/kubernetes/yaml/kubeadm-config.yaml
3、配置kubectl连接集群的config文件(master服务器执行)
mkdir -p ~/.kube cp -i /etc/kubernetes/admin.conf ~/.kube/config chown $(id -u):$(id -g) ~/.kube/config
4、node节点加入集群(node服务器执行)
kubeadm join 192.168.0.71:6443 --token b6s1os.ahm42w99fx7q714x --discovery-token-ca-cert-hash sha256:59313a9ccb4ea0e9b72df434868eb04a237ce0055a8b69bfde4ad36920643828
七、安装flannel网络插件(master服务器执行)
1、下载flannel的部署文件
cd /etc/kubernetes/yaml
wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
2、修改flannel版本
sed -i ‘s/v0.10.0/v0.11.0/g‘ kube-flannel.yml
3、使用kubectl工具部署
kubectl apply -f kube-flannel.yml
文章来自:https://www.cnblogs.com/istio/p/11791981.html