使用Kubeadm部署k8s集群
三步装集群:
基础环境关闭swap
swapoff -a
再把/etc/fstab文件中带有swap的行删了,没有就无视
装这两工具如果没装的话
yum install -y ebtables socat
IPv4 iptables 链设置 CNI插件需要
sysctl net.bridge.bridge-nf-call-iptables=1
墙外安装在国内是很难使用这种方式安装了,推荐查看离线安装的方案
装docker
yum install -y docker
systemctl enable docker && systemctl start docker
装kubeadm kubectl kubelet
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 setenforce 0 yum install -y kubelet kubeadm kubectl systemctl enable kubelet && systemctl start kubelet
关闭SElinux
setenforce 0
cat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system
然后与离线安装启动master无异, kubeadm init
离线安装福利,我已经把所有依赖的镜像,二进制文件,配置文件都打成了包,解决您所有依赖,花了很多时间整理这个,放在了阿里云市场上,希望大家给点小支持
这包里面把大部分操作都写在简单的脚本里面了,在master节点执行 init-master.sh 在node节点执行init-node.sh 安装dashboard执行init-dashboard.sh。
然后就可以在node节点执行master输出出来的join命令了。包的最大价值在于没有任何依赖了,再也不用访问不了国外某网而头疼了。
安装kubelet服务,和kubeadm下载bin文件
把下载好的kubelet kubectl kubeadm 直接拷贝到/usr/bin下面
配置kubelet systemd服务
cat <<EOF > /etc/systemd/system/kubelet.service [Unit] Description=kubelet: The Kubernetes Node Agent Documentation=http://kubernetes.io/docs/ [Service] ExecStart=/usr/bin/kubelet Restart=always StartLimitInterval=0 RestartSec=10 [Install] WantedBy=multi-user.target EOF
cat <<EOF > /etc/systemd/system/kubelet.service.d/10-kubeadm.conf [Service] Environment="KUBELET_KUBECONFIG_ARGS=--bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf" Environment="KUBELET_SYSTEM_PODS_ARGS=--pod-manifest-path=/etc/kubernetes/manifests --allow-privileged=true" Environment="KUBELET_NETWORK_ARGS=--network-plugin=cni --cni-conf-dir=/etc/cni/net.d --cni-bin-dir=/opt/cni/bin" Environment="KUBELET_DNS_ARGS=--cluster-dns=10.96.0.10 --cluster-domain=cluster.local" Environment="KUBELET_AUTHZ_ARGS=--authorization-mode=Webhook --client-ca-file=/etc/kubernetes/pki/ca.crt" Environment="KUBELET_CADVISOR_ARGS=--cadvisor-port=0" Environment="KUBELET_CGROUP_ARGS=--cgroup-driver=cgroupfs" Environment="KUBELET_CERTIFICATE_ARGS=--rotate-certificates=true --cert-dir=/var/lib/kubelet/pki" ExecStart= ExecStart=/usr/bin/kubelet $KUBELET_KUBECONFIG_ARGS $KUBELET_SYSTEM_PODS_ARGS $KUBELET_NETWORK_ARGS $KUBELET_DNS_ARGS $KUBELET_AUTHZ_ARGS $KUBELET_CADVISOR_ARGS $KUBELET_CGROUP_ARGS $KUBELET_CERTIFICATE_ARGS $KUBELET_EXTRA_ARGS EOF
这里需要主意的是要看一下docker的cgroup driver与 --cgroup-driver要一致。 可以用 docker info |grep Cgroup 查看,有可能是systemd 或者 cgroupfs
增加主机名解析
为了防止无法解析主机名,修改/etc/hosts把主机名与ip的映射写上
启动master节点这里得把google的一票镜像想办法弄下来,然而我已经打成了一个
kubeadm init --pod-network-cidr=192.168.0.0/16 --kubernetes-version v1.8.0 --skip-preflight-checks
--pod-network-cidr 参数安装calico网络时需要
--kubernetes-version 不加的话会去请求公网查询版本信息
--skip-preflight-checks 解决一个kubelet目录不空的小bug
看到这些输出时你便成功了:
To start using your cluster, you need to run (as a regular user): mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config You should now deploy a pod network to the cluster. Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at: http://kubernetes.io/docs/admin/addons/ You can now join any number of machines by running the following on each node as root: kubeadm join --token <token> <master-ip>:<master-port> --discovery-token-ca-cert-hash sha256:<hash>
照着执行: