kubernetes 1.5.1 安裝 ( kubeadm centos7.2 阿里云源)

目錄

1.安裝準(zhǔn)備
2.安裝過(guò)程
3.參考文檔

一、安裝準(zhǔn)備

docker加速器

由于國(guó)內(nèi)網(wǎng)絡(luò)問(wèn)題,強(qiáng)烈建議使用docker hub加速器,
阿里云請(qǐng)參考:https://yq.aliyun.com/articles/29941
daocloud請(qǐng)參考:https://www.daocloud.io/mirror#accelerator-doc
我在此記錄為
https://abc.mirror.aliyuncs.com

操作系統(tǒng)

centos 7.2.1511上yum源配置(base epel)
新增k8s源

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

ntp同步配置(chrony.conf)
可選:dns配置,如忽略采用/etc/hosts方式

二、安裝過(guò)程

主機(jī)名相關(guān)

主機(jī)名 ip 角色
kcluster1 10.9.5.91 master
kcluster2 10.9.5.90 node
kcluster3 10.9.5.19 node

如沒(méi)有用dns,需更新所有服務(wù)器的/etc/hosts

安裝docker(所有服務(wù)器)

sudo yum install docker -y

============================================================================================================================================================================================================================================
 Package                                                              Arch                                          Version                                                            Repository                                      Size
============================================================================================================================================================================================================================================
Installing:
 docker                                                               x86_64                                        2:1.10.3-59.el7.centos                                             extras                                          12 M

修改docker啟動(dòng)文件,增加加速器地址
sudo vim /usr/lib/systemd/system/docker.service

ExecStart=/usr/bin/docker-current daemon --registry-mirror=https://abc.mirror.aliyuncs.com \
          --exec-opt native.cgroupdriver=systemd \
          $OPTIONS \
          $DOCKER_STORAGE_OPTIONS \
          $DOCKER_NETWORK_OPTIONS \
          $ADD_REGISTRY \
          $BLOCK_REGISTRY \
          $INSECURE_REGISTRY

啟動(dòng)docker
sudo systemctl daemon-reload && sudo systemctl start docker
sudo systemctl enable docker.service

安裝k8s軟件

sudo yum install socat kubelet kubeadm kubectl kubernetes-cni -y
sudo systemctl enable kubelet.service && sudo systemctl start kubelet.service

配置master(root用戶(hù)下)

設(shè)置環(huán)境變量
export KUBE_REPO_PREFIX=registry.cn-hangzhou.aliyuncs.com/google-containers
KUBE_HYPERKUBE_IMAGE=registry.cn-hangzhou.aliyuncs.com/google-containers/hyperkube-amd64:v1.5.1
KUBE_DISCOVERY_IMAGE=registry.cn-hangzhou.aliyuncs.com/google-containers/kube-discovery-amd64:1.0
KUBE_ETCD_IMAGE=registry.cn-hangzhou.aliyuncs.com/google-containers/etcd-amd64:3.0.4
執(zhí)行配置
kubeadm init --pod-network-cidr="192.168.0.0/16"

執(zhí)行需要一段時(shí)間
最后出現(xiàn)類(lèi)似如下

Your Kubernetes master has initialized successfully!

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:

kubeadm join --token=xxxxxxxxxxxxxxx 10.9.5.91

配置node(root用戶(hù)下)

kubeadm join --token=xxxxxxxxxxxxxx 10.9.5.91
下面是執(zhí)行命令前后的變化

[root@cloud4ourself-kcluster1 ~]# kubectl get nodes
NAME                                STATUS         AGE
cloud4ourself-kcluster1.novalocal   Ready,master   16m
[root@cloud4ourself-kcluster1 ~]# kubectl get nodes
NAME                                STATUS         AGE
cloud4ourself-kcluster1.novalocal   Ready,master   16m
cloud4ourself-kcluster2.novalocal   Ready          3s

配置網(wǎng)絡(luò)(master節(jié)點(diǎn)root用戶(hù)下)

wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

修改網(wǎng)段(也可不修改)和image

由
"Network": "10.244.0.0/16",
改為
"Network": "192.168.0.0/16",

兩個(gè)image
由
image: quay.io/coreos/flannel:v0.7.0-amd64
改為
image: docker.io/4admin2root/flannel:v0.7.0-amd64

執(zhí)行kubectl apply -f kube-flannel.yml
此處也可以改為其他網(wǎng)絡(luò)模式,請(qǐng)參考https://kubernetes.io/docs/admin/addons/

檢查pod狀態(tài)
kubectl --namespace=kube-system get po -o wide
直到所有都為 Running

配置dashboard(master節(jié)點(diǎn)root用戶(hù)下)

kubectl apply -f http://k8s.oss-cn-shanghai.aliyuncs.com/kube/kubernetes-dashboard1.5.0.yaml

kubectl get svc --namespace=kube-system
取得訪問(wèn)地址
http://kcluster1:31810/#/workload?namespace=_all

驗(yàn)證

[root@cloud4ourself-kcluster1 ~]# kubectl create -f https://raw.githubusercontent.com/4admin2root/daocloud/master/my-calc.yaml
replicationcontroller "my-calc-rc" created
service "my-calc-service" created
[root@cloud4ourself-kcluster1 ~]# kubectl create -f https://raw.githubusercontent.com/4admin2root/daocloud/master/my-frontend.yaml
replicationcontroller "my-frontend-rc" created
service "my-frontend-service" created
[root@cloud4ourself-kcluster1 ~]# kubectl get pod
NAME                    READY     STATUS              RESTARTS   AGE
kube-flannel-ds-7f69s   2/2       Running             6          40m
kube-flannel-ds-c7d00   2/2       Running             6          40m
kube-flannel-ds-p3lww   2/2       Running             0          40m
my-calc-rc-6fzh6        0/1       ContainerCreating   0          1m
my-calc-rc-pvhx0        0/1       ContainerCreating   0          1m
my-frontend-rc-jbt2p    0/1       ContainerCreating   0          58s
my-frontend-rc-m2svn    0/1       ContainerCreating   0          58s
[root@cloud4ourself-kcluster1 ~]# kubectl get pod
NAME                    READY     STATUS    RESTARTS   AGE
kube-flannel-ds-7f69s   2/2       Running   6          44m
kube-flannel-ds-c7d00   2/2       Running   6          44m
kube-flannel-ds-p3lww   2/2       Running   0          44m
my-calc-rc-6fzh6        1/1       Running   0          4m
my-calc-rc-pvhx0        1/1       Running   0          4m
my-frontend-rc-jbt2p    1/1       Running   0          4m
my-frontend-rc-m2svn    1/1       Running   0          4m
[root@cloud4ourself-kcluster1 ~]# kubectl get pod -o wide
NAME                    READY     STATUS    RESTARTS   AGE       IP            NODE
kube-flannel-ds-7f69s   2/2       Running   6          45m       10.9.5.90     cloud4ourself-kcluster2.novalocal
kube-flannel-ds-c7d00   2/2       Running   6          45m       10.9.5.19     cloud4ourself-kcluster3.novalocal
kube-flannel-ds-p3lww   2/2       Running   0          45m       10.9.5.91     cloud4ourself-kcluster1.novalocal
my-calc-rc-6fzh6        1/1       Running   0          6m        192.168.2.2   cloud4ourself-kcluster3.novalocal
my-calc-rc-pvhx0        1/1       Running   0          6m        192.168.1.3   cloud4ourself-kcluster2.novalocal
my-frontend-rc-jbt2p    1/1       Running   0          5m        192.168.1.4   cloud4ourself-kcluster2.novalocal
my-frontend-rc-m2svn    1/1       Running   0          5m        192.168.2.3   cloud4ourself-kcluster3.novalocal
[root@cloud4ourself-kcluster1 ~]# kubectl describe svc my-frontend-service
Name:           my-frontend-service
Namespace:      default
Labels:         <none>
Selector:       app=my-frontend
Type:           NodePort
IP:         10.98.166.14
Port:           <unset> 5000/TCP
NodePort:       <unset> 30080/TCP
Endpoints:      192.168.1.4:5000,192.168.2.3:5000
Session Affinity:   None
No events.
[root@cloud4ourself-kcluster1 ~]# kubectl describe svc my-calc-service
Name:           my-calc-service
Namespace:      default
Labels:         <none>
Selector:       app=my-calc
Type:           ClusterIP
IP:         10.105.114.170
Port:           <unset> 5000/TCP
Endpoints:      192.168.1.3:5000,192.168.2.2:5000
Session Affinity:   None
No events.

三、參考文檔

https://kubernetes.io/docs/admin/addons/
https://yq.aliyun.com/articles/66474?commentId=6660

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Kubernetes 搭建有四種方式,簡(jiǎn)單評(píng)價(jià)一下: 1.基于Docker 本地運(yùn)行Kubernetes 先決條件...
    sun363587351閱讀 2,653評(píng)論 0 3
  • 安裝k8s Master高可用集群 主機(jī) 角色 組件 172.18.6.101 K8S Master Kubele...
    jony456123閱讀 8,166評(píng)論 0 9
  • 版權(quán)聲明:原創(chuàng)作品,謝絕轉(zhuǎn)載!否則將追究法律責(zé)任。 前言 最近中國(guó)和印度的局勢(shì)也是愈演愈烈。作為一個(gè)愛(ài)國(guó)青年我有些...
    李偉銘MIng閱讀 2,248評(píng)論 0 5
  • 半湖秋水,幾處輕舟欲碎。容易惜人更自醉,不解思愁誰(shuí)對(duì)? 夕陽(yáng)不念夜雨,青山何悲曉月。偏是孤島西風(fēng),吹散了南柯夢(mèng)。
    Jangle蔣閱讀 848評(píng)論 0 0
  • 一臺(tái)服務(wù)器的承載量是有限的,對(duì)于一個(gè)區(qū)來(lái)說(shuō),平時(shí)可能只需要支持500到1500人左右,這樣一臺(tái)服務(wù)器可能就可以搞定...
    王廣帥閱讀 786評(píng)論 0 3

友情鏈接更多精彩內(nèi)容