目錄
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