Deployment:
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
name: skx
spec:
replicas: 3
template:
metadata:
labels:
app: skx_server
spec:
containers:
PS:注意,在Deployment资源对象中,可以添加Port字段,但此字段仅供用户查看,并不实际生效。
如下:
ports:
SERVICE
kind: Service
apiVersion: v1
metadata:
name: skx-svc
spec:
selector:
app: skx_server
ports:
关联主机:
kind: Service
apiVersion: v1
metadata:
name: skx-svc
spec:
type: NodePort
selector:
app: skx_server
ports:
查找对应的防火墙规则
[root@master ~]# kubectl get svc
[root@master ~]# iptables-save | grep 10.107.64.232
[root@master ~]# iptables-save | grep KUBE-SVC-QDLMDMK46RWAY7QJ
[root@master ~]# iptables-save | grep KUBE-SEP-YPYQNHI3JGSZCBF5
与
[root@master ~]# kubectl get pod -o wide
ip一样
回滚到指定版本:
删除之前创建的资源:
[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:
[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个yaml文件指定不同版本的镜像。
运行一个服务,并记录一个版本信息。
[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
运行并升级Deployment资源,并记录版本信息。
[root@master ~]# kubectl apply -f skx2.yaml --record
deployment.extensions/skx configured
此时可以运行一个关联的Service自愿去验证,升级是否成功
[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 <none> 80:31194/TCP 43h
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 5d17h
skx-svc NodePort 10.96.174.199 <none> 80:30123/TCP 16s
[root@master ~]# curl 10.96.174.199
<h2>songkaixiong | test-web | httpd | v3<h2>
回滚到指定版本。
[root@master ~]# kubectl rollout undo deployment skx --to-revision=1
deployment.extensions/skx rolled back
curl 10.96.174.199
<h2>songkaixiong | test-web | httpd | v1<h2>
用label控制Pod的位置
给node03打上一个标签
[root@master ~]# kubectl label nodes node03 disk=ssd
node/node03 labeled
指定查看node03标签:
[root@master ~]# kubectl get nodes --show-labels | grep node03
node03 Ready <none> 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
不指定查看所有节点标签:
[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 <none> 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 <none> 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:
删除标签:
查看node03的标签:
[root@master ~]# kubectl get nodes --show-labels node03
NAME STATUS ROLES AGE VERSION LABELS
node03 Ready <none> 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标签
[root@master ~]# kubectl label nodes node03 disk-
node/node03 labeled
再次查看node03标签:
[root@master ~]# kubectl get nodes --show-labels node03
NAME STATUS ROLES AGE VERSION LABELS
node03 Ready <none> 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
会找不到,起不来:
[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 <none> <none> <none> <none>
skx-55c4dc6dbc-c2blp 0/1 Pending 0 11s <none> <none> <none> <none>
skx-55c4dc6dbc-zk7gw 0/1 Pending 0 11s <none> <none> <none> <none>
[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
查看详细描述信息
[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
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。