CentOS   发布时间:2022-04-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了CentOS7.3利用kubeadm安装kubernetes1.7.3完整版(官方文档填坑篇)大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

安装前记: 近来容器对企业来说已经不是什么陌生的概念,Kubernetes作为Google开源的容器运行平台,受到了大家的热捧。搭建一套完整的kubernetes平台,也成为试用这套平台必须迈过的坎儿。kubernetes1.5版本以及之前,安装还是相对比较方便的,官方就有通过yum源在centos7安装kubernetes。但是在kubernetes1.6之后,安装就比较繁琐了,需要证书各种认证

安装前记:

近来容器对企业来说已经不是什么陌生的概念,Kubernetes作为Google开源的容器运行平台,受到了大家的热捧。搭建一套完整的kubernetes平台,也成为试用这套平台必须迈过的坎儿。kubernetes1.5版本以及之前,安装还是相对比较方便的,官方就有通过yum源在centos7安装kubernetes。但是在kubernetes1.6之后,安装就比较繁琐了,需要证书各种认证,对于刚接触kubernetes的人来说很不友好,按照官方文档在本地安装“集群”的的话,我觉得你肯定是跑不起来的,除非你突破了GFW的限制,还要懂得怎么样不断修改参数。

令我惊讶的事,漫天都在吹捧kubernetes的强大,居然一篇可以帮助安装的文档都找不到(你可以说我菜,但是我找的官方和非官方文档不下十几篇,无一成功)。

我自己搞了一个星期,把kubernetes1.7.3版本(网络组件选用Calico),终于按照官方文档+填坑的方式部署成功,写此文希望能帮助更多的人部署kubernetes1.7成功。

安装

安装准备

  • 操作系统:CentOS7.3
[root@centos7-base-ok]# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (CorE)
  • 安装机器:k8s-1为master节点,k8s-2、k8s-3为slave节点
[root@centos7-base-ok]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

k8s-1 192.168.80.28
k8s-2 192.168.80.35
k8s-3 192.168.80.14

安装步骤

安装docker 1.12(所有节点)

1.新建docker.repo文件,将文件移动到/etc/yum.repos.d/目录下

[root@centos7-base-ok]# cat /etc/yum.repos.d/docker.repo
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/7/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg

2.运行yum命令,找到需要安装的docker版本

10:21 [root@centos7-base-ok]# yum list|grep docker | sort -r
python2-avocado-plugins-runner-docker.noarch
python-dockerpty.noarch                 0.4.1-6.el7                    epel
python-dockerfile-parse.noarch          0.0.5-1.el7                    epel
python-docker-scripts.noarch            0.4.4-1.el7                    epel
python-docker-pycreds.noarch            1.10.6-1.el7                   extras
python-docker-py.noarch                 1.10.6-1.el7                   extras
kdocker.x86_64                          4.9-1.el7                      epel
golang-github-fsouza-go-dockerclient-devel.x86_64
docker.x86_64                           2:1.12.6-32.git88a4867.el7.centos
docker-v1.10-migrator.x86_64            2:1.12.6-32.git88a4867.el7.centos
docker-unit-test.x86_64                 2:1.12.6-32.git88a4867.el7.centos
docker-registry.x86_64                  0.9.1-7.el7                    extras
docker-registry.noarch                  0.6.8-8.el7                    extras
docker-python.x86_64                    1.4.0-115.el7                  extras
docker-novolume-plugin.x86_64           2:1.12.6-32.git88a4867.el7.centos
docker-lvm-plugin.x86_64                2:1.12.6-32.git88a4867.el7.centos
docker-logrotate.x86_64                 2:1.12.6-32.git88a4867.el7.centos
docker-latest.x86_64                    1.13.1-13.gitb303bf6.el7.centos
docker-latest-v1.10-migrator.x86_64     1.13.1-13.gitb303bf6.el7.centos
docker-latest-logrotate.x86_64          1.13.1-13.gitb303bf6.el7.centos
docker-forWARD-journald.x86_64          1.10.3-44.el7.centos           extras
docker-ENGIne.x86_64                    17.05.0.ce-1.el7.centos        dockerrepo
docker-ENGIne.x86_64                    1.12.6-1.el7.centos            @dockerrepo
docker-ENGIne-selinux.noarch            17.05.0.ce-1.el7.centos        @dockerrepo
docker-ENGIne-debuginfo.x86_64          17.05.0.ce-1.el7.centos        dockerrepo
docker-diStribution.x86_64              2.6.1-1.el7                    extras
docker-devel.x86_64                     1.3.2-4.el7.centos             extras
docker-compose.noarch                   1.9.0-5.el7                    epel
docker-common.x86_64                    2:1.12.6-32.git88a4867.el7.centos
docker-client.x86_64                    2:1.12.6-32.git88a4867.el7.centos
docker-client-latest.x86_64             1.13.1-13.gitb303bf6.el7.centos
cockpit-docker.x86_64                   141-3.el7.centos               extras

3.找到对应版本后,执行yum install -y 包名+版本号,安装1.12版本的docker-ENGIne

[root@centos7-base-ok]# yum install -y docker-ENGIne.x86_64-1.12.6-1.el7.centos

4.执行docker version命令,验证docker安装版本,执行docker run命令,验证docker是否安装成功

[root@centos7-base-ok]# docker version
Client:
 Version:      1.12.6
 API version:  1.24
 Go version:   go1.6.4
 Git commit:   78d1802
 Built:        Tue Jan 10 20:20:01 2017
 OS/Arch:      linux/amd64

Server:
 Version:      1.12.6
 API version:  1.24
 Go version:   go1.6.4
 Git commit:   78d1802
 Built:        Tue Jan 10 20:20:01 2017
 OS/Arch:      linux/amd64

5.设置开机启动,启动容器,docker安装完成

[root@centos7-base-ok]# systemctl enbale docker && systemctl start docker

安装kubectl、kubelet、kubeadm(根据需求在不同节点安装)

1.新建kubernetes.repo文件,将文件移动到/etc/yum.repos.d/目录下(所有节点)

[root@centos7-base-ok]# cat /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0

2.通过yum安装kubectl、kubelet、kubeadm(所有节点)

[root@centos7-base-ok]# cat /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0

3.修改kubelet配置,启动kubelet(所有节点)

编辑10-kubeadm.conf的文件修改cgroup-driver配置:

[root@centos7-base-ok]# cat /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
[service]
Environment="KUBELET_KUBECONfig_ARGS=--kubeconfig=/etc/kubernetes/kubelet.conf --require-kubeconfig=true"
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"
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_EXTRA_ARGS

将“--cgroup-driver=systems”修改成为“--cgroup-driver=cgroupfs”,重新启动kubelet。

[root@centos7-base-ok]# systemctl restart kubelet

4.下载安装k8s依赖镜像

@H_414_16@master节点:

REPOSITORY                                               TAG                 IMAGE ID            CREATED             SIZE
quay.io/calico/kube-policy-controller                    v0.7.0              fe3174230993        3 days ago          21.94 MB
kubernetesdashboarddev/kubernetes-dashboard-amd64        head                e2cadb73b2df        5 days ago          136.5 MB
quay.io/calico/node                                      v2.4.1              7643422fdf0f        6 days ago          277.4 MB
gcr.io/google_containers/kube-controller-manager-amd64   v1.7.3              d014f402b272        11 days ago         138 MB
gcr.io/google_containers/kube-apiserver-amd64            v1.7.3              a1cc3a3d8d0d        11 days ago         186.1 MB
gcr.io/google_containers/kube-scheduler-amd64            v1.7.3              51967bf607d3        11 days ago         77.2 MB
gcr.io/google_containers/kube-proxy-amd64                v1.7.3              54d2a8698e3c        11 days ago         114.7 MB
quay.io/calico/cni                                       v1.10.0             88ca805c8ddd        13 days ago         70.25 MB
gcr.io/google_containers/kubernetes-dashboard-amd64      v1.6.3              691a82db1ecd        2 weeks ago         139 MB
quay.io/coreos/etcd                                      v3.1.10             47bb9dd99916        4 weeks ago         34.56 MB
gcr.io/google_containers/k8s-dns-sidecar-amd64           1.14.4              38BAC66034a6        7 weeks ago         41.81 MB
gcr.io/google_containers/k8s-dns-kube-dns-amd64          1.14.4              a8e00546bcf3        7 weeks ago         49.38 MB
gcr.io/google_containers/k8s-dns-dnsmasq-nAnny-amd64     1.14.4              f7f45b9cb733        7 weeks ago         41.41 MB
gcr.io/google_containers/etcd-amd64                      3.0.17              243830dae7dd        5 months ago        168.9 MB
gcr.io/google_containers/pause-amd64                     3.0                 99e59f495ffa        15 months ago       746.9 kB

node节点:

[root@centos7-base-ok]# docker images
REPOSITORY                                            TAG                 IMAGE ID            CREATED             SIZE
kubernetesdashboarddev/kubernetes-dashboard-amd64     head                e2cadb73b2df        5 days ago          137MB
quay.io/calico/node                                   v2.4.1              7643422fdf0f        6 days ago          277MB
gcr.io/google_containers/kube-proxy-amd64             v1.7.3              54d2a8698e3c        11 days ago         115MB
quay.io/calico/cni                                    v1.10.0             88ca805c8ddd        13 days ago         70.3MB
gcr.io/google_containers/kubernetes-dashboard-amd64   v1.6.3              691a82db1ecd        2 weeks ago         139MB
Nginx                                                 latest              b8efb18f159b        2 weeks ago         107MB
Hello-world                                           latest              1815c82652c0        2 months ago        1.84kB
gcr.io/google_containers/pause-amd64                  3.0                 99e59f495ffa        15 months ago       747kB

5.利用kubeadm初始化服务(master节点)

[root@centos7-base-ok]# kubeadm init --pod-network-cidr=192.168.0.0/16 --apiserver-advertise-address=0.0.0.0 --apiserver-cert-extra-sans=192.168.80.28,192.168.80.14,192.168.80.35,127.0.0.1,k8s-1,k8s-2,k8s-3,192.168.0.1 --skip-preflight-checks

参数说明:

参数名称 必选 参数说明
pod-network-cidr Yes For certain networking solutions the Kubernetes master can also play a role in allocating network ranges (CIDRs) to each node. This includes many cloud providers and flAnnel. You can specify a subnet range that will be broken down and handed out to each node with the --pod-network-cidr flag. This should be a minimum of a /16 so controller-manager is able to assign /24 subnets to each node in the cluster. If you are using flAnnel with this manifest you should use --pod-network-cidr=10.244.0.0/16. Most CNI based networking solutions do not require this flag.
apiserver-advertise-address Yes This is the address the API Server will advertise to other members of the cluster. This is also the address used to construct the suggested kubeadm join line at the end of the init process. If not set (or set to 0.0.0.0) then IP for the default interface will be used.
apiserver-cert-extra-sans Yes Additional hostnames or IP addresses that should be added to the Subject Alternate Name section for the certificate that the API Server will use. If you expose the API Server through a load balancer and public DNS you Could specify this with.

其它的 kubeadm 参数设置请参照 官方文档

6.做一枚安静的美男子,等待安装成功,安装成功后你会看到日志如下(master节点):

[apiclient] All control plane components are healthy after 22.003243 seconds
[token] Using token: 33729e.977f7b5d0a9b5f3e
[apiconfig] Created RBAC rules
[addons] Applied essential addon: kube-proxy
[addons] Applied essential addon: kube-dns

Your Kubernetes master has initialized successfully!

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 xxxxxxx 192.168.80.28:6443

7.创建kube的目录,添加kubectl配置(master节点)

@H_892_30@mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config

8.用 kubectl 添加网络组件Calico(master节点)

kubectl apply -f http://docs.projectcalico.org/v2.4/getTing-started/kubernetes/installation/hosted/kubeadm/1.6/calico.yaml

9.确认安装是否成功(master节点)

9.1 打开你的/var/log/messages,查看是否有报错,理论上,执行完上一步过去5分钟,日志应该不会有任何错误出现,如果持续报错,并且过了10分钟错误依然没有消失,检查之前的步骤是否有问题

9.2 运行 kubectl get pods --all-namespaces 查看结果,如果STATUS都为Running,恭喜你,你的master已经安装成功了。

[root@centos7-base-ok]# kubectl get pods --all-namespaces
NAMESPACE     NAME                                       READY     STATUS    RESTARTS   AGE
default       Nginx-app-1666850838-4z2tb                 1/1       Running   0          3d
kube-system   calico-etcd-0ssdd                          1/1       Running   0          3d
kube-system   calico-node-1zfxd                          2/2       Running   1          3d
kube-system   calico-node-s2gfs                          2/2       Running   1          3d
kube-system   calico-node-xx30v                          2/2       Running   1          3d
kube-system   calico-policy-controller-336633499-wgl8j   1/1       Running   0          3d
kube-system   etcd-k8s-1                                 1/1       Running   0          3d
kube-system   kube-apiserver-k8s-1                       1/1       Running   0          3d
kube-system   kube-controller-manager-k8s-1              1/1       Running   0          3d
kube-system   kube-dns-2425271678-trmxx                  3/3       Running   1          3d
kube-system   kube-proxy-79kkh                           1/1       Running   0          3d
kube-system   kube-proxy-n1g6j                           1/1       Running   0          3d
kube-system   kube-proxy-vccr6                           1/1       Running   0          3d
kube-system   kube-scheduler-k8s-1                       1/1       Running   0          3d

10.安装node节点,执行在master节点执行成功输出的日志语句(node节点执行)

[root@centos7-base-ok]# kubeadm join --token xxxxxxxx 192.168.80.28:6443
  1. 验证子节点,在master节点执行 kubectl get nodes 查看节点状态。
[root@centos7-base-ok]# kubectl get nodes
NAME      STATUS    AGE       VERSION
k8s-1     Ready     3d        v1.7.3
k8s-2     Ready     3d        v1.7.3
k8s-3     Ready     3d        v1.7.3

12.恭喜你,你可以开心的进行kubernetes1.7.3之旅了

安装后记

Kubernetes,想说爱你不容易啊,欢迎其它团队或者个人与我们团队进行交流,有意向可以评论区给我留言。

补充:目前官方说dashboard的HEAD版本支持1.7,但是我试了下dashboard确实不行,希望官方加快修复,还有就是多些错误定位的方法,否则很难提出具体的问题。

大佬总结

以上是大佬教程为你收集整理的CentOS7.3利用kubeadm安装kubernetes1.7.3完整版(官方文档填坑篇)全部内容,希望文章能够帮你解决CentOS7.3利用kubeadm安装kubernetes1.7.3完整版(官方文档填坑篇)所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。