真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

kubernetes中Deployment配置

Deployment對(duì)象,顧名思義,是用于部署應(yīng)用的對(duì)象。它使Kubernetes中最常用的一個(gè)對(duì)象,它為ReplicaSet和Pod的創(chuàng)建提供了一種聲明式的定義方法,從而無(wú)需像前兩篇文章中那樣手動(dòng)創(chuàng)建ReplicaSet和Pod對(duì)象(使用Deployment而不直接創(chuàng)建ReplicaSet是因?yàn)镈eployment對(duì)象擁有許多ReplicaSet沒有的特性,例如滾動(dòng)升級(jí)和回滾)。

Deployment:
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
name: skx
spec:
replicas: 3
template:
metadata:
labels:
app: skx_server
spec:
containers:

成都創(chuàng)新互聯(lián)公司主營(yíng)大石橋網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營(yíng)網(wǎng)站建設(shè)方案,成都APP應(yīng)用開發(fā),大石橋h5微信小程序定制開發(fā)搭建,大石橋網(wǎng)站營(yíng)銷推廣歡迎大石橋等地區(qū)企業(yè)咨詢

  • name: httpd-test
    image: 192.168.1.10:5000/httpd:v1
    ports:
    • containerPort: 80

PS:注意,在Deployment資源對(duì)象中,可以添加Port字段,但此字段僅供用戶查看,并不實(shí)際生效。
如下:
ports:

  • containerPort: 80

SERVICE

kind: Service
apiVersion: v1
metadata:
name: skx-svc
spec:
selector:
app: skx_server
ports:

  • protocol: TCP
    port: 80
    targetPort: 80

關(guān)聯(lián)主機(jī):
kind: Service
apiVersion: v1
metadata:
name: skx-svc
spec:
type: NodePort
selector:
app: skx_server
ports:

  • protocol: TCP
    port: 80
    targetPort: 80
    nodePort: 30123
    更改pod訪問界面:
    [root@master ~]# kubectl exec -it skx-694cc5db89-45nvk /bin/bash
    root@skx-694cc5db89-45nvk:/usr/local/apache2# echo no.1 > htdocs/index.html
    root@skx-694cc5db89-45nvk:/usr/local/apache2# exit
    查看規(guī)則:
    [root@master ~]# iptables-save
    SNAT:Source NAT(源地址轉(zhuǎn)換) DNAT:Destnation(目標(biāo)地址轉(zhuǎn)換) MASQ:動(dòng)態(tài)的源地址轉(zhuǎn)換
    Service實(shí)現(xiàn)的負(fù)載均衡使用的時(shí)iptables規(guī)則。IPVS
    10.107.64.232
    KUBE-SVC-QDLMDMK46RWAY7QJ

查找對(duì)應(yīng)的防火墻規(guī)則
[root@master ~]# kubectl get svc
kubernetes中Deployment配置

[root@master ~]# iptables-save | grep 10.107.64.232
kubernetes中Deployment配置

[root@master ~]# iptables-save | grep KUBE-SVC-QDLMDMK46RWAY7QJ
kubernetes中Deployment配置

[root@master ~]# iptables-save | grep KUBE-SEP-YPYQNHI3JGSZCBF5
kubernetes中Deployment配置


[root@master ~]# kubectl get pod -o wide

kubernetes中Deployment配置
ip一樣

回滾到指定版本:
刪除之前創(chuàng)建的資源:
[root@master ~]# kubectl delete -f skx-svc.yaml
service "skx-svc" deleted
[root@master ~]# kubectl delete -f skx.yaml
deployment.extensions "skx" deleted

[root@master ~]# kubectl get deployments.
No resources found.
[root@master ~]# vim skx.yaml
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
name: skx
spec:
revisionHistoryLimit: 10   //添加
replicas: 3
template:
metadata:
labels:
app: skx_server
spec:
containers:

  • name: httpd-test
    image: 192.168.1.10:5000/httpd:v1
    ports:
    • containerPort: 80
      準(zhǔn)備三個(gè)版本所使用的私有鏡像,來(lái)模擬每次升級(jí)不同的鏡像。
      [root@master ~]# mv skx.yaml skx1.yaml
      [root@master ~]# cp skx1.yaml skx2.yaml
      [root@master ~]# cp skx1.yaml skx3.yaml

[root@master ~]# vim skx1.yaml

15行:

    image: 192.168.1.10:5000/httpd:v1

[root@master ~]# vim skx2.yaml

15行:

    image: 192.168.1.10:5000/httpd:v2

[root@master ~]# vim skx3.yaml

15行:

    image: 192.168.1.10:5000/httpd:v3

此處3個(gè)yaml文件指定不同版本的鏡像。
運(yùn)行一個(gè)服務(wù),并記錄一個(gè)版本信息。
[root@master ~]# kubectl apply -f skx1.yaml --record
deployment.extensions/skx created
[root@master ~]# kubectl apply -f skx2.yaml --record
deployment.extensions/skx configured
[root@master ~]# kubectl apply -f skx3.yaml --record
deployment.extensions/skx configured
查看有哪些版本信息
[root@master ~]# kubectl rollout history deployment skx
deployment.extensions/skx
REVISION  CHANGE-CAUSE
1         kubectl apply --filename=skx1.yaml --record=true
2         kubectl apply --filename=skx2.yaml --record=true
3         kubectl apply --filename=skx3.yaml --record=true

運(yùn)行并升級(jí)Deployment資源,并記錄版本信息。
[root@master ~]# kubectl apply -f skx2.yaml --record
deployment.extensions/skx configured
此時(shí)可以運(yùn)行一個(gè)關(guān)聯(lián)的Service自愿去驗(yàn)證,升級(jí)是否成功
[root@master ~]# kubectl apply -f skx-svc.yaml
service/skx-svc created

[root@master ~]# kubectl get svc
NAME         TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
httpd-svc    NodePort    10.97.81.154            80:31194/TCP   43h
kubernetes   ClusterIP   10.96.0.1              443/TCP        5d17h
skx-svc      NodePort    10.96.174.199          80:30123/TCP   16s

[root@master ~]# curl 10.96.174.199

songkaixiong | test-web | httpd | v3

回滾到指定版本。
[root@master ~]# kubectl rollout undo deployment skx --to-revision=1
deployment.extensions/skx rolled back
curl 10.96.174.199

songkaixiong | test-web | httpd | v1

用label控制Pod的位置
給node03打上一個(gè)標(biāo)簽
[root@master ~]# kubectl label nodes node03 disk=ssd
node/node03 labeled
指定查看node03標(biāo)簽:
[root@master ~]# kubectl get nodes --show-labels | grep node03
node03   Ready       5d17h   v1.15.0   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,disk=ssd,kubernetes.io/arch=amd64,kubernetes.io/hostname=node03,kubernetes.io/os=linux
不指定查看所有節(jié)點(diǎn)標(biāo)簽:
[root@master ~]# kubectl get nodes --show-labels
NAME     STATUS   ROLES    AGE     VERSION   LABELS
master   Ready    master   5d17h   v1.15.0   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=master,kubernetes.io/os=linux,node-role.kubernetes.io/master=
node02   Ready       5d17h   v1.15.0   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=node02,kubernetes.io/os=linux
node03   Ready       5d17h   v1.15.0   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,disk=ssd,kubernetes.io/arch=amd64,kubernetes.io/hostname=node03,kubernetes.io/os=linux
刪除skx1資源:
[root@master ~]# kubectl delete  -f skx1.yaml
deployment.extensions "skx" deleted

[root@master ~]# kubectl delete  -f skx-svc.yaml
service "skx-svc" deleted

修改skx1.yaml配置文件:
[root@master ~]# vim skx1.yaml
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
name: skx
spec:
revisionHistoryLimit: 10
replicas: 3
template:
metadata:
labels:
app: skx_server
spec:
containers:

  • name: httpd-test
    image: 192.168.1.10:5000/httpd:v1
    ports:
    • containerPort: 80
      nodeSelector:             //添加節(jié)點(diǎn)選擇器
      disk: ssd               //和標(biāo)簽內(nèi)容一致
      [root@master ~]# kubectl apply -f skx1.yaml
      deployment.extensions/skx created
      三臺(tái)都在node03上運(yùn)行:
      [root@master ~]# kubectl get pod -o wide
      NAME                   READY   STATUS    RESTARTS   AGE   IP            NODE     NOMINATED NODE   READINESS GATES
      skx-55c4dc6dbc-7ztl9   1/1     Running   0          73s   10.244.2.27   node03            
      skx-55c4dc6dbc-jsms7   1/1     Running   0          73s   10.244.2.28   node03            
      skx-55c4dc6dbc-rfss7   1/1     Running   0          73s   10.244.2.26   node03            

刪除標(biāo)簽:
查看node03的標(biāo)簽:
[root@master ~]# kubectl get nodes --show-labels node03
NAME     STATUS   ROLES    AGE     VERSION   LABELS
node03   Ready       5d17h   v1.15.0   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,disk=ssd,kubernetes.io/arch=amd64,kubernetes.io/hostname=node03,kubernetes.io/os=linux
刪除node03標(biāo)簽
[root@master ~]# kubectl label nodes node03 disk-
node/node03 labeled
再次查看node03標(biāo)簽:
[root@master ~]# kubectl get nodes --show-labels node03
NAME     STATUS   ROLES    AGE     VERSION   LABELS
node03   Ready       5d17h   v1.15.0   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=node03,kubernetes.io/os=linux

刪除資源:
[root@master ~]# kubectl delete deployments. skx
deployment.extensions "skx" deleted
重新生成:
[root@master ~]# kubectl apply -f skx1.yaml
deployment.extensions/skx unchanged
會(huì)找不到,起不來(lái):
[root@master ~]# kubectl get pod -o wide
NAME                   READY   STATUS    RESTARTS   AGE   IP       NODE     NOMINATED NODE   READINESS GATES
skx-55c4dc6dbc-8rpl6   0/1     Pending   0          11s                
skx-55c4dc6dbc-c2blp   0/1     Pending   0          11s                
skx-55c4dc6dbc-zk7gw   0/1     Pending   0          11s                

[root@master ~]# kubectl get pod -n kube-system
NAME                             READY   STATUS    RESTARTS   AGE
coreDNS-5c98db65d4-52cdm         1/1     Running   3          5d17h
coredns-5c98db65d4-sl96w         1/1     Running   4          5d17h
etcd-master                      1/1     Running   3          5d17h
kube-apiserver-master            1/1     Running   3          5d17h
kube-controller-manager-master   1/1     Running   3          5d17h
kube-flannel-ds-amd64-9vnsc      1/1     Running   4          5d17h
kube-flannel-ds-amd64-tdzrm      1/1     Running   2          5d17h
kube-flannel-ds-amd64-tvl2q      1/1     Running   5          5d17h
kube-proxy-492jr                 1/1     Running   2          5d17h
kube-proxy-gccnb                 1/1     Running   3          5d17h
kube-proxy-klznh                 1/1     Running   2          5d17h
kube-scheduler-master            1/1     Running   4          5d17h

查看master日志:
[root@master ~]# kubectl logs -n kube-system kube-scheduler-master
查看詳細(xì)描述信息
[root@master ~]# kubectl describe pod skx-55c4dc6dbc-8rpl6
查看日志
[root@master ~]# kubectl logs -n kube-system kube-scheduler-master
查看kubectl日志
[root@master ~]#  less /var/log/messages | grep kubelet


網(wǎng)站標(biāo)題:kubernetes中Deployment配置
標(biāo)題網(wǎng)址:http://weahome.cn/article/jhhcgd.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部