Kubernetes安装

部署方式:通过kubeadm安装步骤(一个master节点和两个node节点)

  1. master,nodes:安装kubelet,kubeadm,docker
  2. master:kubeadm init
  3. nodes:kubeadm join(文档:https://github.com/kubernetes/kubeadm/blob/master/docs/design/design_v1.8.md)
  4. 关闭firewall和iptables

创建docker-ce和kubernetes的yum仓库:

[root@master ~]# cd /etc/yum.repo.d/
[root@master ~]# wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[root@master ~]# cat > kubernetes.repo <<EOF
[kubernetes]
name=Kubernetes Repo
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
enabled=1
EOF

安装docker-ce kubelet kubeadm kubectl

[root@master ~]# yum -y install docker-ce kubelet kubeadm kubectl
[root@master ~]# systemctl stop firewalld #关闭防火墙
[root@master ~]# systemctl disable firewalld
[root@master ~]# systemctl enable docker kubelet

创建/etc/sysctl.d/k8s.conf文件,并配置kubelet不加载swap

[root@master ~]# cat > /etc/sysctl.d/k8s.conf <<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF
[root@master ~]# cat > /etc/sysconfig/kubelet<<EOF
KUBELET_EXTRA_ARGS=--fail-swap-on=false
EOF

因为天朝防火墙的关系,在中国访问不了google的docker仓库,但是我们可以在阿里云上找到需要的镜像,下载下来,然后重新打上标签即可,可以使用下面的脚本下载所需镜像

#!/bin/bash
image_aliyun=(kube-apiserver-amd64:v1.12.1 kube-controller-manager-amd64:v1.12.1 kube-scheduler-amd64:v1.12.1 kube-proxy-amd64:v1.12.1 pause-amd64:3.1 etcd-amd64:3.2.24)
for image in ${image_aliyun[@]}
do
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/$image
docker tag  registry.cn-hangzhou.aliyuncs.com/google_containers/$image k8s.gcr.io/${image/-amd64/}
done

初始化

kubeadm init --apiserver-advertise-address=192.168.175.4 --pod-network-cidr=10.244.0.0/16 --ignore-preflight-errors=Swap

保存节点加入的命令:#kubeadm join 192.168.175.4:6443 --token wyy67p.9wmda1iw4o8ds0c5 --discovery-token-ca-cert-hash sha256:3de3e4401de1cdf3b4c778ad1ac3920d9f7b15ca34b4c5ebe44d92e60d1290e0 保存代用
如果忘记可以使用kubeadm token create --print-join-command
[root@master ~]# mkdir -p $HOME/.kube
[root@master ~]# cp -i /etc/kubernetes/admin.conf $HOME/.kube/config

部署网络插件flannel

 kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml如果镜像下载不了,可以使用上面的方式在aliyun下载xiangy

将node节点加入到集群:

[root@node1 ~]# systemctl enable docker kubelet
[root@node1 ~]# kubeadm join 192.168.175.4:6443 --token wyy67p.9wmda1iw4o8ds0c5 --discovery-token-ca-cert-hash sha256:3de3e4401de1cdf3b4c778ad1ac3920d9f7b15ca34b4c5ebe44d92e60d1290e0
posted @ 2018-10-24 16:39  谭普利特  阅读(175)  评论(0编辑  收藏  举报