kubernets的基本概念和作用就不赘述了,google一下什么都知道了,直接进入正题,记录一下采坑和安装的过程。
环境准备:
centos7.2 x86_64 192.168.147.191 master k8s.masterdengchao.com##小插曲k8s.master.com居然有人注册了,搞的我在初始化的时候等了半天也没有反应,确实有点坑人,所以后面改了主机名
centos7.2 x86_64 192.168.147.192 master node1.com
centos7.2 x86_64 192.168.147.193 master k8s.node2.com
kubernets启动之前需要安装docker,但是现再最新版的v1.10也支持到docker17.03.这个一定要注意,要不然启动不成功。
安装docker17.03:
master节点:
安装docker 17.03依赖包:
yum install -y yum-utils device-mapper-persistent-data lvm2 wget net-tools
wget https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-selinux-17.03.2.ce-1.el7.centos.noarch.rpm
wget https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-17.03.2.ce-1.el7.centos.x86_64.rpm
yum localinstall docker-ce-selinux-17.03.2.ce-1.el7.centos.noarch.rpm docker-ce-17.03.2.ce-1.el7.centos.x86_64.rpm -y
systemctl enable docker
systemctl start docker
配置hosts文件三台节点都要配置:
cat /etc/hosts
192.168.147.191 k8s.masterdengchao.com
192.168.147.192 k8s.node1.com
192.168.147.193 k8s.node2.com
配置kubernetsyum仓库:
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
setenforce 0
yum install -y kubelet kubeadm kubectl
systemctl enable kubelet && systemctl start kubelet
这里启动的时候会报错,kubelet启动不起来。
修改一下配置文件:
cat /usr/lib/sysctl.d/00-system.conf
Kernel sysctl configuration file
#
For binary values,0 is disabled,1 is enabled. See sysctl(8) and
sysctl.conf(5) for more details.
Disable netfilter on bridges.
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-arptables = 0
使用一下命令:
sed -i 's/net.bridge.bridge-nf-call-ip6tables = 0/net.bridge.bridge-nf-call-ip6tables = 1/' /usr/lib/sysctl.d/00-system.conf
sed -i 's/net.bridge.bridge-nf-call-iptables = 0/net.bridge.bridge-nf-call-iptables = 1/' /usr/lib/sysctl.d/00-system.conf
报错和解决办法如下:
提示找不到ca文件,直接先初始化,会自动下载ca文件:
kubeadm init --pod-network-cidr 10.10.0.0/24 --ignore-preflight-errors all
然后再启动
systemctl daemon-reload && systemctl start kubelet
在初始化就没有问题了
kubeadm init --pod-network-cidr 10.10.0.0/24 --ignore-preflight-errors all
然后安装提示操作:
mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config
会生产一个token这个需要记下来到node节点上面去执行:
kubeadm join 192.168.147.191:6443 --token l6mql3.61w91hpwzzzul53t --discovery-token-ca-cert-hash sha256:03e3dded073878045e1831d610254904a451ff574de7bf8f1a5d812f40195947
错误:Failed to run Kubelet: Running with swap on is not supported,please disable swap!
解决:
echo 'Environment="KUBELET_EXTRA_ARGS=--fail-swap-on=false"' >> /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
修改:/etc/systemd/system/kubelet.service.d/10-kubeadm.conf
Environment="KUBELET_CGROUP_ARGS=--cgroup-driver=systemd" 将systemd修改为cgroupfs
sed -i 's/Environment="KUBELET_CGROUP_ARGS=--cgroup-driver=systemd"/Environment="KUBELET_CGROUP_ARGS=--cgroup-driver=cgroupfs"/' /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
错误:
Container runtime network not ready: NetworkReady=false reason:NetworkPluginNotReady message:docker: network plugin is not ready: cni config uninitialized
解决:
/etc/systemd/system/kubelet.service.d/10-kubeadm.conf注释掉network一行
#Environment="KUBELET_NETWORK_ARGS=--network-plugin=cni --cni-conf-dir=/etc/cni/net.d --cni-bin-dir=/opt/cni/bin"
创建网络:
wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/k8s-manifests/kube-flannel-legacy.yml
kubectl create -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/k8s-manifests/kube-flannel-legacy.yml
##记得修改网段
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/k8s-manifests/kube-flannel-rbac.yml
master节点的安装就基本完成了。
node节点上面:
1.安装docker并启动
2.安装kubernets并启动
3.执行kubeadm join 192.168.147.191:6443 --token l6mql3.61w91hpwzzzul53t --discovery-token-ca-cert-hash sha256:03e3dded073878045e1831d610254904a451ff574de7bf8f1a5d812f40195947 加入到机器
在master节点查看状态:
至此安装完成,但是我的网络比较慢,docker在下载镜像。