Kubernetes 1 4 基礎篇 kubeadm方式安裝
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=Kubernetes
baseurl=http://yum.kubernetes.io/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 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=Kubernetes
baseurl=http://yum.kubernetes.io/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
EOF
#
- 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 docker
Created 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 kubelet
Created 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/sh
usage(){
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 1
fi
CNT=0
if [ _"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
[[email protected] ~]# 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-dns
Kubernetes 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
[[email protected] ~]#
- 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 nodes
NAME STATUS AGE
liumiaocn 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-kube
daemonset "weave-net" created
[root@liumiaocn ~]#
- 1
- 2
- 3
版本確認
[[email protected] ~]# kubectl version
Client 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"}
[[email protected] ~]# kubeadm version
kubeadm 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"}
[[email protected] ~]#
- 1
- 2
- 3
- 4
- 5
- 6
kubeadm確實有其獨到之處,比1.4之前的kubernetes-ansible或者minikube相比方便很多。另外1.4版本的UI也有所強化,我們將在後面進行進一步的介紹。
再分享一下我老師大神的人工智慧教程吧。零基礎!通俗易懂!風趣幽默!希望你也加入到我們人工智慧的隊伍中來!https://www.cnblogs.com/captainbed