$cat /etc/hosts
10.255.101.69 k8s-master
10.255.101.70 k8s-node-1
10.255.101.71 k8s-node-2
2. 禁用防火墙
$systemctl stop firewalld.service
$systemctl disable firewalld.service
3. 禁用SELINUX:
$setenforce 0
$cat /etc/selinux/config
SELINUX=disabled
4. 创建/etc/sysctl.d/k8s.conf并添加一下内容
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
执行以下命令使修改生效
$ modprobe br_netfilter
$ sysctl -p /etc/sysctl.d/k8s.conf
1.2安装docker
$yum install -y yum-utils device-mapper-persistent-data lvm2查看当前Docker版本
yum list docker-ce.x86_64 --showduplicates |sort -r
docker-ce.x86_64 17.09.0.ce-1.el7.centos docker-cestable
docker-ce.x86_64 17.06.2.ce-1.el7.centos docker-cestable
docker-ce.x86_64 17.06.1.ce-1.el7.centos docker-cestable
docker-ce.x86_64 17.06.0.ce-1.el7.centos docker-cestable
docker-ce.x86_64 17.03.2.ce-1.el7.centos docker-cestable
docker-ce.x86_64 17.03.1.ce-1.el7.centos docker-cestable
docker-ce.x86_64 17.03.0.ce-1.el7.centos docker-cestable
Kubernetes 1.8已经针对Docker的1.11.2, 1.12.6, 1.13.1,17.03做了验证,这里在各节点安装docker17.03版本
yum makecache fast
yum install -y --setopt=obsoletes=0 \
docker-ce-17.03.2.ce-1.el7.centos \
docker-ce-selinux-17.03.2.ce-1.el7.centos
systemctl start docker
systemctl enable docker
禁用iptables filter表中FOWARD链,这样会引起Kubernetes集群中跨Node的Pod无法通信,在各docker节点执行以下命令
iptables -P FORWARD ACCEPT
可在docker的systemd unit文件中以ExecStartPost加入上面的命令
$vim /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
ExecStartPost=/usr/sbin/iptables -P FORWARD ACCEPT
systemctl daemon-reload
systemctl restart docker
echo "Pulling Images..."
echo "==>kube-apiserver:"
docker pull mirrorgooglecontainers/kube-apiserver-amd64:v1.9.4
docker tag mirrorgooglecontainers/kube-apiserver-amd64:v1.9.4 gcr.io/google_containers/kube-apiserver-amd64:v1.9.4
echo "==>kube-controller-manager:"
docker pull mirrorgooglecontainers/kube-controller-manager-amd64:v1.9.4
docker tag mirrorgooglecontainers/kube-controller-manager-amd64:v1.9.4
gcr.io/google_containers/kube-controller-manager-amd64:v1.9.4
echo "==>kube-scheduler:"
docker pull mirrorgooglecontainers/kube-scheduler-amd64:v1.9.4
docker tag mirrorgooglecontainers/kube-scheduler-amd64:v1.9.4
gcr.io/google_containers/kube-scheduler-amd64:v1.9.4
echo "==>kube-proxy:"
docker pull mirrorgooglecontainers/kube-proxy-amd64:v1.9.4
docker tag mirrorgooglecontainers/kube-proxy-amd64:v1.9.4
gcr.io/google_containers/kube-proxy-amd64:v1.9.4
echo "==>k8s-dns-sidecar:"
docker pull mirrorgooglecontainers/k8s-dns-sidecar-amd64:1.14.7echo "
==>k8s-dns-dnsmasq-nanny:"
docker pull mirrorgooglecontainers/k8s-dns-dnsmasq-nanny-amd64:1.14.7
docker tag mirrorgooglecontainers/k8s-dns-dnsmasq-nanny-amd64:1.14.7
gcr.io/google_containers/k8s-dns-dnsmasq-nanny-amd64:1.14.7
echo "==>etcd:"
docker pull mirrorgooglecontainers/etcd-amd64:3.1.11
docker tag mirrorgooglecontainers/etcd-amd64:3.1.11
gcr.io/google_containers/etcd-amd64:3.1.11
echo "==>pause:"
docker pull mirrorgooglecontainers/pause-amd64:3.0
docker tag mirrorgooglecontainers/pause-amd64:3.0
gcr.io/google_containers/pause-amd64:3.0
docker pull mirrorgooglecontainers/kubernetes-dashboard-amd64:v1.8.3
docker tag mirrorgooglecontainers/kubernetes-dashboard-amd64:v1.8.3
gcr.io/google_containers/kubernetes-dashboard-amd64:v1.8.3
2.2 Node拉取镜像
echo "Pulling Images..."
echo "==>kube-proxy:"
docker pull mirrorgooglecontainers/kube-proxy-amd64:v1.9.4
docker tag mirrorgooglecontainers/kube-proxy-amd64:v1.9.4
gcr.io/google_containers/kube-proxy-amd64:v1.9.4
echo "==>pause:"
docker pull mirrorgooglecontainers/pause-amd64:3.0
docker tag mirrorgooglecontainers/pause-amd64:3.0 gcr.io/google_containers/pause-amd64:3.0
echo "==>kube-dashborad:"
docker pull mirrorgooglecontainers/kubernetes-dashboard-amd64:v1.9.4
docker tag mirrorgooglecontainers/kubernetes-dashboard-amd64:v1.9.4 gcr.io/google_containers/kubernetes-dashboard-amd64:v1.9.4
echo "==>heapster-influxdb:"
docker pull mirrorgooglecontainers/heapster-influxdb-amd64:v1.3.3
docker tag mirrorgooglecontainers/heapster-influxdb-amd64:v1.3.3 gcr.io/google_containers/heapster-influxdb-amd64:v1.3.3
echo "==>heapster-grafana:"
docker pull mirrorgooglecontainers/heapster-grafana-amd64:v4.4.3
docker tag mirrorgooglecontainers/heapster-grafana-amd64:v4.4.3 gcr.io/google_containers/heapster-grafana-amd64:v4.4.3
echo "==>heapster:"
docker pull mirrorgooglecontainers/heapster-amd64:v1.4.2
docker tag mirrorgooglecontainers/heapster-amd64:v1.4.2 gcr.io/google_containers/heapster-amd64:v1.4.2
3. 安装kubeadm和kubelet(所有节点)
cat < /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-
x86_64/
enabled=1
gpgcheck=0
EOF
curl https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
yum makecache fast
yum install kubelet-1.9.4-0 kubeadm-1.9.4-0 kubectl-1.9.4-0
kubernetes文档中kubelet的启动参数:
--cgroup-driver string Driver that the kubelet uses to manipulate cgroups
on the host.
Possible values: 'cgroupfs', 'systemd' (default "cgroupfs")
默认值为cgroupfs,但是yum安装kubelet,kubeadm时,生成的10-kubeadm.conf参数变成了systemd,查看/etc/systemd/system/kubelet.service.d/10-kubeadm.conf,包含以下内容
Environment="KUBELET_CGROUP_ARGS=--cgroup-driver=systemd"
docker info 打印docker信息:
docker info
......
Server Version: 17.03.2-ce
......
Cgroup Driver: cgroupfs
说明docker 17.03使用的Cgroup Driver是cgroupfs,于是修改所有节点docker的Cgroup Driver使其与kubelet一致,修改或创建/etc/docker/daemon.json,加入:
{
"exec-opts": ["native.cgroupdriver=systemd"]
}
重启docker:systemctl restart docker
设置开机启动kubelet:systemctl enable kubelet.service
k8s1.8开始要求关闭系统Swap,如果不关闭,kubelet将无法启动,于是关闭:
swapoff -a
4. 使用kubeadm初始化集群
kubeadm init \ --kubernetes-version=v1.9.4 \ --pod-network-cidr=10.244.0.0/16 \ --apiserver-advertise-address=10.255.101.69 #