1. 实验步骤
- 环境准备
yum -y update
关闭防火墙
systemctl stop firewalld
关闭SELinux
setenforce 0
关闭swap
swapoff -a
修改主机名称
hostnamectl set-hostname master
- 配置修改
添加hosts,快速解析IP地址与域名
vim /etc/hosts
172.xx.xx.xx master
【操作注意】这里的IP是自己的私网IP
将桥接的 IPv4 流量传递到 iptables 的链
【操作注意】按I进入编辑模式,按ESC退出编辑模式后按shift+:组合键,输入wq进行保存。
cat > /etc/sysctl.d/k8s.conf << EOF
net.bridge.bridge-nf-call-ip6tables = 1net.bridge.bridge-nf-call-iptables = 1
EOF
生效
sysctl --system
- 安装docker和k8s
拉取安装文件
wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo
安装docker
yum -y install docker-ce-18.06.3.ce-3.el7
开机自启和启动Docker
systemctl enable docker && systemctl start docker
添加yum源
cat > /etc/yum.repos.d/kubernetes.repo << EOF
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
安装kubeadm,kubelet和kubectl
yum -y install kubelet-1.18.0 kubeadm-1.18.0 kubectl-1.18.0
开机自启kubelet
systemctl enable kubelet
- 部署主机
【操作注意】这里的172.20.xxxx 为自己的私网IP
kubeadm init \
--apiserver-advertise-address=172.20.xx.xx \
--image-repository registry.aliyuncs.com/google_containers \
--service-cidr=10.96.0.0/12 \
--pod-network-cidr=10.244.0.0/16
创建 kube 目录
mkdir -p $HOME/.kube
拷贝配置文件
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
指定用户组
chown $(id -u):$(id -g) $HOME/.kube/config
master主机上安装pod网络插件
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml