ip 主機名 角色 操做系統 192.168.157.130 master 主 centeos7.6+ 192.168.157.131 ode1 節點 Centos7.6+ 192.168.157.132 node2 節點 Centos7.6+
systemctl stop firewalld.service systemctl stop iptables.service systemctl disable firewalld.service systemctl disable iptables.service
將 SELinux 設置爲 permissive 模式(將其禁用)node
setenforce 0 sed -i 's/^SELINUX=enforcing$/SELINUX=disabled/' /etc/selinux/config
關閉swaplinux
swapoff -a # 永久關閉, 須要註釋掉/dev開頭的文字 vim /etc/fstab
以下:git
UUID=ed95c595-4813-480e-992b-85b1347842e8 / ext4 defaults 1 1 # /dev/vgdata/lvdata /data ext4 defaults 0 0
modprobe br_netfilter cat <<EOF > /etc/sysctl.d/k8s.conf net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 EOF
使配置生效github
sysctl -p /etc/sysctl.d/k8s.conf ls /proc/sys/net/bridge
安裝基本服務docker
yum install -y net-tools epel-release vim yum-utils device-mapper-persistent-data lvm2
配置docker和安裝dockerjson
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo yum install -y docker-ce-18.06.0.ce systemctl enable docker systemctl start docker cat <<EOF > /etc/docker/daemon.json { "insecure-registries":["0.0.0.0/0"], "exec-opts": ["native.cgroupdriver=systemd"] } EOF systemctl restart docker
配置k8syum源vim
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
安裝kubectl、kubelet、kubenetes-cni、kubeadmcentos
yum install -y kubectl-1.14.1 kubelet-1.14.1 kubernetes-cni-0.7.5 kubeadm-1.14.1
設置開機啓動api
systemctl enable kubelet
準備k8s 須要的docker 鏡像(由於外網緣由,不能下載鏡像)網絡
cat > pullimages.sh << EOF # 添加以下內容 docker pull mirrorgooglecontainers/kube-apiserver-amd64:v1.14.1 docker pull mirrorgooglecontainers/kube-controller-manager-amd64:v1.14.1 docker pull mirrorgooglecontainers/kube-scheduler-amd64:v1.14.1 docker pull mirrorgooglecontainers/kube-proxy-amd64:v1.14.1 docker pull mirrorgooglecontainers/pause:3.1 docker pull mirrorgooglecontainers/etcd-amd64:3.3.10 docker pull coredns/coredns:1.3.1 docker tag mirrorgooglecontainers/kube-controller-manager-amd64:v1.14.1 k8s.gcr.io/kube-controller-manager:v1.14.1 docker tag mirrorgooglecontainers/kube-scheduler-amd64:v1.14.1 k8s.gcr.io/kube-scheduler:v1.14.1 docker tag mirrorgooglecontainers/kube-apiserver-amd64:v1.14.1 k8s.gcr.io/kube-apiserver:v1.14.1 docker tag mirrorgooglecontainers/kube-proxy-amd64:v1.14.1 k8s.gcr.io/kube-proxy:v1.14.1 docker tag mirrorgooglecontainers/pause:3.1 k8s.gcr.io/pause:3.1 docker tag mirrorgooglecontainers/etcd-amd64:3.3.10 k8s.gcr.io/etcd:3.3.10 docker tag coredns/coredns:1.3.1 k8s.gcr.io/coredns:1.3.1 docker rmi mirrorgooglecontainers/kube-apiserver-amd64:v1.14.1 docker rmi mirrorgooglecontainers/kube-controller-manager-amd64:v1.14.1 docker rmi mirrorgooglecontainers/kube-scheduler-amd64:v1.14.1 docker rmi mirrorgooglecontainers/kube-proxy-amd64:v1.14.1 docker rmi mirrorgooglecontainers/pause:3.1 docker rmi mirrorgooglecontainers/etcd-amd64:3.3.10 docker rmi coredns/coredns:1.3.1 EOF # 執行腳本 sh pullimages.sh
集羣初始化(請記錄初始化最後打印出的kubeadm join 信息)(IP根據實際狀況修改)
kubeadm init \ --kubernetes-version=v1.14.1 \ --pod-network-cidr=10.244.0.0/16 \ --apiserver-advertise-address=`ifconfig eth0 |awk '{print $2}'|sed -n "2,1p"` 記錄: kubeadm join ${IP_ADDRESS}:6443 --token p2f3ud.l44djf21s0nj7a5y \ --discovery-token-ca-cert-hash sha256:866d6131855e1847bcec7481a184b42ea8616bbe95a9ffcf8dfcc64cdb38a905 # 複製配置 mkdir ~/.kube cp -i /etc/kubernetes/admin.conf ~/.kube/config chown $(id -u):$(id -g) ~/.kube/config
wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml kubectl apply -f kube-flannel.yml
使 master 節點參與工做負載
kubectl describe node | grep Taint kubectl taint nodes --all node-role.kubernetes.io/master-
注意: 【子節點執行】子節點加入集羣(IP根據實際狀況修改)
kubeadm join ${IP_ADDRESS}:6443 --token p2f3ud.l44djf21s0nj7a5y \ --discovery-token-ca-cert-hash sha256:866d6131855e1847bcec7481a184b42ea8616bbe95a9ffcf8dfcc64cdb38a905 # 確認日誌無報錯 # 複製配置 mkdir ~/.kube 拷貝主節點的 ~/.kube/config 到 ~/.kube(命令:scp -r ${IP_ADDRESS}:/root/.kube/config ~/.kube/) chown $(id -u):$(id -g) ~/.kube/config # 在主節點查詢 Ready 說明節點加入集羣正常 kubectl get nodes