分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow
也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!
kubernetes在9月份推出了1.4的版本,在这个版本中最招人眼球的就是它推出了kubeadm的方式进行安装,简化了很多流程。终于,至少这个版本的kubernetes像docker1.12内置的swarm一样方便的创建集群了。本文将会介绍一下如何在centos7下安装单节点可用的集群。亲测可用。
2016/9/26 kubernetes发布了1.4版,自称“Making it easy to run on Kubernetes anywhere”,还增加了一些特性,该版本最引起关注的可能就是kubeadm的引入了。kubernetes1.4的新增特性中第一个被介绍的就是“两条语句创建集群(Cluster creation with two commands)”了。
kubernetes 1.4新特性
- 两条语句创建集群
- Stateful应用支持的扩展
- Cluster federation API additions
- 容器安全支持(Pod Security Policy+Apparmor)
- Infrastructure enhancements(swagger2.0的支持等)
- Dashboard UI(能完成CLI的90%操作)
- …
安装准备
项番 | 详细 |
---|---|
No.1 | 一台或多台CentOS7 |
No.2 | 大于或等于1G的内存 |
No.3 | 网络可以连接 |
Step 1/4 :安装kubelet和kubeadm
具体步骤参看如下:
# cat <<EOF > /etc/yum.repos.d/kubernetes.repo[kubernetes]name=Kubernetesbaseurl=http://yum.kubernetes.io/repos/kubernetes-el7-x86_64enabled=1gpgcheck=1repo_gpgcheck=1gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpgEOF# setenforce 0# yum install -y docker kubelet kubeadm kubectl kubernetes-cni# systemctl enable docker && systemctl start docker# systemctl enable kubelet && systemctl start kubelet
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
注意事项:因为https://packages.cloud.google.com/yum/doc/yum-key.gpg,这个可能很多用户无法访问,可以不用check,设定gpgcheck=0,直接执行即可。
# cat <<EOF > /etc/yum.repos.d/kubernetes.repo[kubernetes]name=Kubernetesbaseurl=http://yum.kubernetes.io/repos/kubernetes-el7-x86_64enabled=1gpgcheck=0EOF#
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
安装参照
[root@liumiaocn ~]# cat <<EOF > /etc/yum.repos.d/kubernetes.repo> [kubernetes]> name=Kubernetes> baseurl=http://yum.kubernetes.io/repos/kubernetes-el7-x86_64> enabled=1> gpgcheck=0> EOF[root@liumiaocn ~]# setenforce 0[root@liumiaocn ~]# yum install -y docker kubelet kubeadm kubectl kubernetes-cni 2>&1 >/tmp/k8s_install.log[root@liumiaocn ~]# systemctl enable docker && systemctl start dockerCreated symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.[root@liumiaocn ~]# systemctl enable kubelet && systemctl start kubeletCreated symlink from /etc/systemd/system/multi-user.target.wants/kubelet.service to /etc/systemd/system/kubelet.service.[root@liumiaocn ~]#
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
Step 2/4: 初始化Master
命令:kubeadm init
- 1
安装参照:提前将google相关的一些image下载到本地会加快构建集群的速度,应该国内的因为网络的原因无法下载,因此将初始化时需要的6个image提前下载到本地。为了方便,可以使用如下脚本直接执行(参数为PREPARE),其将会直接从liumiaocn的dockerhub下直接pull后rename然后untag。
#!/bin/shusage(){ echo "Usage: $0 ACTION " echo " ACTION: LIST|PREPARE"}PROXY="kube-proxy-amd64:v1.4.0"DISCOVERY="kube-discovery-amd64:1.0"SCHEDULER="kube-scheduler-amd64:v1.4.0"CONTROLLER="kube-controller-manager-amd64:v1.4.0"APISERVER="kube-apiserver-amd64:v1.4.0"PAUSE="pause-amd64"ALL_IMAGES="${PROXY} ${DISCOVERY} ${SCHEDULER} ${CONTROLLER} ${APISERVER} ${PAUSE}"ACTION="$1"if [ $# -ne 1 ]; then usage exit 1fiCNT=0if [ _"PREPARE" = _"${ACTION}" ]; then echo "Now begin to pull images from liumiaocn" for image in ${ALL_IMAGES} do CNT=`expr ${CNT} + 1` echo "No.${CNT} : ${image} pull begins ..." docker pull liumiaocn/${image} echo "No.${CNT} : ${image} pull ends ..." echo "No.${CNT} : ${image} rename ..." docker tag liumiaocn/${image} gcr.io/google_containers/${image} echo "No.${CNT} : ${image} untag ..." docker rmi liumiaocn/${image} echo "" done echo "All images have been pulled to local as following" docker images |egrep 'kube|pause'else echo "All images of local for k8s as following" docker images |egrep 'kube|pause'fi
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
初始化命令:kubeadm init
[root@liumiaocn ~]# kubeadm init<master/tokens> generated token: "9a5d26.9223a9e6bb57b85c"<master/pki> created keys and certificates in "/etc/kubernetes/pki"<util/kubeconfig> created "/etc/kubernetes/kubelet.conf"<util/kubeconfig> created "/etc/kubernetes/admin.conf"<master/apiclient> created API client configuration<master/apiclient> created API client, waiting for the control plane to become ready<master/apiclient> all control plane components are healthy after 55.613825 seconds<master/apiclient> waiting for at least one node to register and become ready<master/apiclient> first node is ready after 2.251018 seconds<master/discovery> created essential addon: kube-discovery, waiting for it to become ready<master/discovery> kube-discovery is ready after 5.219802 seconds<master/addons> created essential addon: kube-proxy<master/addons> created essential addon: kube-dnsKubernetes master initialised successfully!You can now join any number of machines by running the following on each node:kubeadm join --token 9a5d26.9223a9e6bb57b85c 16.157.246.203[root@liumiaocn ~]#
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
[root@liumiaocn ~]# kubectl taint nodes --all dedicated-node "liumiaocn" tainted[root@liumiaocn ~]# kubectl get nodesNAME STATUS AGEliumiaocn Ready 5m[root@liumiaocn ~]#
- 1
- 2
- 3
- 4
- 5
- 6
总结: kubeadm init进行不下去的主要原因.
原因1:CentOS7下kubernetes1.4的安装有个bug需要执行setenforce 0设定selinux才可,据kubernetes的issue说明后续的版本应该不会再有问题。
原因2:事前container没有提前下载下来,因为各种网络问题一直无法继续
原因3:CentOS7下,因为网络设备编号没有eth0而产生的问题,有可能是当前kubernetes的一个bug,毕竟还只是内测程度的版本,要求不要太高。可以查看系统/var/log/messages即可看出问题所在。
Step 3/4: kubeadm join
kubeadm init之后master就ready了,然后使用一个一个地kubeadm join就完成了集群的创建。方式跟今年合体到docker里面的swarm如出一辙。
看来这个是kubernetes对docker的一大反击,docker在模仿kubernetes的容器管理的时候,kubernetes也开始模仿docker swarm创建集群。
命令:kubeadm join --token 9a5d26.9223a9e6bb57b85c 16.157.246.203
- 1
Step 4/4: weave设定
[root@liumiaocn ~]# kubectl apply -f https://git.io/weave-kubedaemonset "weave-net" created[root@liumiaocn ~]#
- 1
- 2
- 3
版本确认
[root@liumiaocn ~]# kubectl versionClient Version: version.Info{Major:"1", Minor:"4", GitVersion:"v1.4.0", GitCommit:"a16c0a7f71a6f93c7e0f222d961f4675cd97a46b", GitTreeState:"clean", BuildDate:"2016-09-26T18:16:57Z", GoVersion:"go1.6.3", Compiler:"gc", Platform:"linux/amd64"}Server Version: version.Info{Major:"1", Minor:"4", GitVersion:"v1.4.0", GitCommit:"a16c0a7f71a6f93c7e0f222d961f4675cd97a46b", GitTreeState:"clean", BuildDate:"2016-09-26T18:10:32Z", GoVersion:"go1.6.3", Compiler:"gc", Platform:"linux/amd64"}[root@liumiaocn ~]# kubeadm versionkubeadm version: version.Info{Major:"1", Minor:"5+", GitVersion:"v1.5.0-alpha.0.1534+cf7301f16c0363-dirty", GitCommit:"cf7301f16c036363c4fdcb5d4d0c867720214598", GitTreeState:"dirty", BuildDate:"2016-09-27T18:10:39Z", GoVersion:"go1.6.3", Compiler:"gc", Platform:"linux/amd64"}[root@liumiaocn ~]#
- 1
- 2
- 3
- 4
- 5
- 6
kubeadm确实有其独到之处,比1.4之前的kubernetes-ansible或者minikube相比方便很多。另外1.4版本的UI也有所强化,我们将在后面进行进一步的介绍。
给我老师的人工智能教程打call!http://blog.csdn.net/jiangjunshow
![这里写图片描述](https://i-blog.csdnimg.cn/blog_migrate/2e19ffb3303a490d20ea5d00dd397156.gif)