Centos7 一步一步搭建K8S环境
程序员文章站
2022-03-01 13:01:20
...
Centos7 一步一步搭建K8S环境
前提条件
Centos7 安装
百度网盘链接:https://pan.baidu.com/s/1vERNTMEC37ZgKAEcYUgvKA 提取码:7cpp
主机名 | 操作系统版本 | docker version | kubelet version | flannel version |
---|---|---|---|---|
k8s_master | Centos 7 | 18.09.6 | V1.14.2 | V0.11.0 |
k8s_node01 | Centos 7 | 18.09.6 | V1.14.2 | V0.11.0 |
k8s_node02 | Centos 7 | 18.09.6 | V1.14.2 | V0.11.0 |
初始化
# yum update -y
# yum install -y pip curl git zsh wget
# sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
安装docker
# yum install -y yum-utils device-mapper-persistent-data lvm2
# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
# yum install -y docker-ce-18.09.6 docker-ce-cli-18.09.6 containerd.io
# mkdir -p /etc/docker
# tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://v16stybc.mirror.aliyuncs.com"],
"exec-opts": ["native.cgroupdriver=systemd"]
}
EOF
# systemctl daemon-reload
# systemctl restart docker
K8S 安装准备
环境准备
# systemctl stop firewalld.service
# systemctl disable firewalld.service
# swapoff -a
# sed -i.bak '/swap/s/^/#/' /etc/fstab
# sysctl net.bridge.bridge-nf-call-iptables=1
# sysctl net.bridge.bridge-nf-call-ip6tables=1
# cat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
# sysctl -p /etc/sysctl.d/k8s.conf
# 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
# yum clean all
# yum -y makecache
# yum install -y kubelet-1.14.2 kubeadm-1.14.2 kubectl-1.14.2
# systemctl enable kubelet && systemctl start kubelet
镜像准备
K8S相关镜像:https://pan.baidu.com/s/1dnZyL6AZda1CAJof341Jgg
提取码:i4qn
# docker load -i coredns_1.3.1.tar
# docker load -i etcd_3.3.10.tar
# docker load -i flannel_v0.11.0-amd64.tar
# docker load -i kube-apiserver_v1.14.2.tar
# docker load -i kube-controller-manager_v1.14.2.tar
# docker load -i kube-proxy_v1.14.2.tar
# docker load -i kubernetes-dashboard-amd64_1.10.0.tar
# docker load -i kube-scheduler_v1.14.2.tar
# docker load -i pause_3.1.tar
K8S master 安装
前提: 通过Vmware 完成克隆虚拟机 k8s-master
# cat >> /etc/hosts << EOF
192.168.137.100 k8s-master
192.168.137.101 k8s-node01
192.168.137.102 k8s-node02
EOF
# hostnamectl set-hostname k8s-master
# echo 'FORWARD_IPV4=YES' >> /etc/sysconfig/network
# echo "1" > /proc/sys/net/ipv4/ip_forward
# kubeadm init --apiserver-advertise-address 192.168.137.100 --pod-network-cidr=192.168.0.0/16
# mkdir -p $HOME/.kube
# cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
# chown $(id -u):$(id -g) $HOME/.kube/config
# kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
K8S node01 安装
前提: 通过Vmware 完成克隆虚拟机 k8s-node01
# cat >> /etc/hosts << EOF
192.168.137.100 k8s-master
192.168.137.101 k8s-node01
192.168.137.102 k8s-node02
EOF
# hostnamectl set-hostname k8s-node01
# echo 'FORWARD_IPV4=YES' >> /etc/sysconfig/network
# echo "1" > /proc/sys/net/ipv4/ip_forward
# kubeadm join 192.168.137.100:6443 --token tiowt5.3duz1b0hwmxcz4tz \
--discovery-token-ca-cert-hash sha256:9f1cc4746ede82e697a8fc4711feba9fcc3c4ecd323d14da220b1834cd7dfa89
K8S node02 安装
前提: 通过Vmware 完成克隆虚拟机 k8s-node02
# cat >> /etc/hosts << EOF
192.168.137.100 k8s-master
192.168.137.101 k8s-node01
192.168.137.102 k8s-node02
EOF
# hostnamectl set-hostname k8s-node02
# echo 'FORWARD_IPV4=YES' >> /etc/sysconfig/network
# echo "1" > /proc/sys/net/ipv4/ip_forward
# kubeadm join 192.168.137.100:6443 --token tiowt5.3duz1b0hwmxcz4tz \
--discovery-token-ca-cert-hash sha256:9f1cc4746ede82e697a8fc4711feba9fcc3c4ecd323d14da220b1834cd7dfa89
推荐阅读
-
JDK 安装与环境配置配置——Android开发第一步
-
Centos7系统下搭建.NET Core2.0+Nginx+Supervisor环境
-
新手和企业如何一步步搭建自己的网站?
-
CentOS7 LNMP+phpmyadmin环境搭建 第三篇phpmyadmin安装
-
CentOS7 LNMP+phpmyadmin环境搭建 第一篇虚拟机及centos7安装
-
CentOS7 LNMP+phpmyadmin环境搭建 第二篇LNMP环境搭建教程
-
一步一步搭建前端监控系统:如何定位前端线上问题?
-
centos7 PHP环境搭建 GD库 等插件安装方法
-
Linux环境基于CentOS7 搭建部署Docker容器
-
ssm整合总结(一)--第一步之使用maven搭建一个web项目