[笔记] CentOS 7 部署 Kubernetes 集群自动化脚本部分
install 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
systemctl start docker
install kubectl
cat << EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF
# Disabling SELinux by running setenforce 0 is required to allow containers to access the host filesystem,which is required by pod networks for example. You have to do this until SELinux support is improved in the kubelet.
setenforce 0
yum install -y kubelet kubeadm
# if cannot start kubelet,check system journal: `error: Failed to run Kubelet: Failed to create kubelet: misconfiguration: kubelet cgroup driver: "systemd" is different from docker cgroup driver: "cgroupfs"`
sed -i 's|=systemd|=cgroupfs|' /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
systemctl enable kubelet && systemctl start kubelet
init kubernetes
// master
kubeadm init
# wait for message that show `kubeadm join --token <token>`
[addition/network] kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/v0.8.0/Documentation/kube-flannel.yml
// slave
kubeadm join --token <token>
use kubectl
export KUBECONFIG=/etc/kubernetes/admin.conf
kubectl get nodes