直接写过程,有些描述就省略了
关于kubeadm安装k8s 1.11.2版本可以查看:https://www.cnblogs.com/shansongxian/p/9753603.html
首先查看下k8s 1.12版的changlog有哪些改动
github地址:https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG-1.12.md#changelog-since-v1120
![](https://img2018.cnblogs.com/blog/1056769/201810/1056769-20181018154628127-441815071.png)
终于支持docker 18.06了
首先说下环境:
系统:centos 7 1708版本
地址:192.168.237.128(演示环境无额外Nodes节点机器)
docker: 18.06
k8s: 1.12.1
最低配置:2核2G
第一步调整下系统内核参数,hosts修改,加载ipvs模块,关闭swap,selinux,firewall,系统时间
192.168.237.128 k8s-master
cat <<EOF > /etc/sysctl.d/k8s.conf net.ipv4.ip_forward = 1 net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 vm.swappiness = 0 EOF sysctl --system
yum install ipset ipvsadm conntrack-tools.x86_64 -y cat > /etc/sysconfig/modules/ipvs.modules <<EOF #!/bin/bash ipvs_modules="ip_vs ip_vs_lc ip_vs_wlc ip_vs_rr ip_vs_wrr ip_vs_lblc ip_vs_lblcr ip_vs_dh ip_vs_sh ip_vs_fo ip_vs_nq ip_vs_sed ip_vs_ftp nf_conntrack_ipv4" for kernel_module in ${ipvs_modules}; do /sbin/modinfo -F filename ${kernel_module} > /dev/null 2>&1 if [ $? -eq 0 ]; then /sbin/modprobe ${kernel_module} fi done EOF chmod 755 /etc/sysconfig/modules/ipvs.modules sh /etc/sysconfig/modules/ipvs.modules && lsmod | grep ip_vs
systemctl stop firewalld && systemctl disable firewalld sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config sed -i 's/.*swap.*/#&/' /etc/fstab
echo "*/5 * * * * /usr/sbin/ntpdate time.windows.com > /dev/null 2>&1" >> /var/spool/cron/root
重启下系统
第二步安装docker
yum install container-selinux libseccomp libtool-ltdl -y rpm -ivh https://mirrors.ustc.edu.cn/docker-ce/linux/centos/7/x86_64/stable/Packages/docker-ce-18.06.1.ce-3.el7.x86_64.rpm systemctl start docker && systemctl enable docker cat > /etc/docker/daemon.json << EOF { "registry-mirrors": ["https://8vtb3cuu.mirror.aliyuncs.com"] } EOF systemctl restart docker
第三步安装kubeadm
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 默认安装kubeadm kubectl kubelet cri-tools kubernetes-cni socat 查看安装版本 yum list kubeadm --showduplicates yum list kubectl --showduplicates yum list kubelet --showduplicates yum list kubernetes-cni --showduplicates 不指定版本默认安装最新版1.12.1 yum install kubeadm -y
第四步利用kubeadm安装k8国内无法下载谷歌镜像,使用anjia0532镜像,更改为默认kubeadm中的镜像名称
kubeadm config images list --kubernetes-version v1.12.1 使用shell脚本快速操作: #!/bin/bash KUBE_VERSION=v1.12.1 KUBE_PAUSE_VERSION=3.1 ETCD_VERSION=3.2.24 DNS_VERSION=1.2.2 ANJIA_URL=anjia0532/google-containers GCR_UR=k8s.gcr.io images=(kube-apiserver:${KUBE_VERSION} kube-controller-manager:${KUBE_VERSION} kube-scheduler:${KUBE_VERSION} kube-proxy:${KUBE_VERSION} pause:${KUBE_PAUSE_VERSION} etcd:${ETCD_VERSION} coredns:${DNS_VERSION}) for imageName in ${images[@]} ; do docker pull $ANJIA_URL.$imageName docker tag $ANJIA_URL.$imageName $GCR_UR/$imageName docker rmi $ANJIA_URL.$imageName done 打印kubeadm默认配置,kubeadm配置文件按照默认配置进行修改 kubeadm config print-default kubeadm v1.12 kubeProxy默认已经使用ipvs模式,在v1.11.x中还需要在配置中指定,如果服务器有多个网卡地址,还需要指定出口IP,使用参数--apiserver-advertise-address=<ip-address> 必需要指定的参数是Pod的网段,使用参数--pod-network-cidr 除了使用参数方式外还可以创建kubeadm-config.yaml文件进行定制化 这里使用加载yaml配置文件的方式,也是推荐的方法 指定10.244.0.0/16网段作为Pod的地址段,也是Flannel网络的默认网段 kind and apiVersion是需要在yaml中强制拥有的信息, apiVersion: kubeadm.k8s.io/v1alpha3 kind: ClusterConfiguration kubernetesVersion: v1.12.1 networking: dnsDomain: cluster.local podSubnet: 10.244.0.0/16 --- apiVersion: kubeproxy.config.k8s.io/v1alpha1 kind: KubeProxyConfiguration mode: "ipvs" 执行Init创建集群 systemctl enable kubelet.service kubeadm init --config kubeadm-config.yaml
kubeadm会默认安装Coredns kube-proxy两个插件 root用户直接添加环境变量/etc/profile kubectl需要读取授权信息访问kubernetes集群 export KUBECONFIG=/etc/kubernetes/admin.conf 非root用户则执行屏幕输出的 mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config
记录输出的Kubeadm join语句,用于添加工作节点 查看集群状态 kubectl get cs 查看节点,pods kube get nodes kube get pods,svc -n kube-system
第五步添加Pod网络组件
必须在任何应用程序之前部署网络。此外,CoreDNS将不会在安装网络之前启动 注意,kubeadm默认设置更安全的群集并强制使用RBAC。确保您的网络清单支持RBAC 我这里master和Nodes都在同一台机器,默认Master是不允许运行用户Pod的 执行: kubectl taint nodes k8s-master node-role.kubernetes.io/master:NoSchedule- 部署Flannel网络 wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml 有多个网卡的话,需要在kube-flannel.yml中使用--iface参数指定集群主机内网网卡的名称,(集群中的主机通过内网网段通信)否则可能会出现dns无法解析。flanneld启动参数加上--iface=<iface-name> args: - --ip-masq - --kube-subnet-mgr - --iface=ens33 #默认Pod网段(为kubeadm.yaml定义的Pod网段,如果不是10.244.0.0/16则需要修改) net-conf.json: | { "Network": "10.244.0.0/16", "Backend": { "Type": "vxlan" } } #应用flannel kubectl apply -f kube-flannel.yml 若出现imagepullerror无法下载quay.io/coreos/flannel:v0.10.0-amd64时,使用下面方法: docker pull registry.cn-shenzhen.aliyuncs.com/cp_m/flannel:v0.10.0-amd64 docker tag registry.cn-shenzhen.aliyuncs.com/cp_m/flannel:v0.10.0-amd64 quay.io/coreos/flannel:v0.10.0-amd64 docker rmi registry.cn-shenzhen.aliyuncs.com/cp_m/flannel:v0.10.0-amd64
第六步 配置treak ingress
kubectl apply -f https://raw.githubusercontent.com/containous/traefik/master/examples/k8s/traefik-rbac.yaml #使用DaemonSets部署方式 kubectl apply -f https://raw.githubusercontent.com/containous/traefik/master/examples/k8s/traefik-ds.yaml wget https://raw.githubusercontent.com/containous/traefik/master/examples/k8s/ui.yaml 修改ui.yaml中host域名 apiVersion: extensions/v1beta1 kind: Ingress metadata: name: traefik-web-ui namespace: kube-system spec: rules: - host: www.abc.com http: paths: - path: / backend: serviceName: traefik-web-ui servicePort: web 添加hosts映射访问域名
![](https://img2018.cnblogs.com/blog/1056769/201810/1056769-20181025162214469-135939314.png)
第七步配置Dashboard
下载anjia镜像 docker pull anjia0532/google-containers.kubernetes-dashboard-amd64:v1.10.0 docker tag anjia0532/google-containers.kubernetes-dashboard-amd64:v1.10.0 k8s.gcr.io/kubernetes-dashboard-amd64:v1.10.0 docker rmi anjia0532/google-containers.kubernetes-dashboard-amd64:v1.10.0 wget https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml 在yaml文件末尾加上 type: NodePort 使用此方法暴露dashboard服务 创建rdbc授权文件kubernetes-dashboard-rbac.yaml apiVersion: v1 kind: ServiceAccount metadata: name: admin-user namespace: kube-system --- apiVersion: rbac.authorization.k8s.io/v1beta1 kind: ClusterRoleBinding metadata: name: admin-user roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: cluster-admin subjects: - kind: ServiceAccount name: admin-user namespace: kube-system #应用定义文件 kubectl apply -f kubernetes-dashboard.yaml kubectl apply -f kubernetes-dashboard-rbac.yaml #查看admin-user用户token kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}') #复制token,在浏览器上选择令牌方式 使用火狐浏览器,https://ip:port
![](https://img2018.cnblogs.com/blog/1056769/201810/1056769-20181025174203264-666560608.png)