概述
deployment名字为:nginx,保证运行3个Pod.service名字为:nginx-svc。映射到主机端口:31234.
[root@kbs01 ~]# vim nginx.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: nginx
spec:
replicas: 3
template:
metadata:
labels:
name: nginx
spec:
containers:
- name: nginx
image: 192.168.226.10:5000/nginx
---
apiVersion: v1
kind: Service
metadata:
name: nginx-svc
spec:
selector:
name: nginx
type: NodePort
ports:
- port: 80 t
targetPort: 80
nodePort: 31234
[root@kbs01 ~]# kubectl apply -f nginx.yaml
deployment.extensions/nginx createdservice/nginx-svc created
查看pod和service:
[root@kbs01 ~]# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx-698ff786b7-45hq6 1/1 Running 0 12s 10.244.1.3 kbs02
nginx-698ff786b7-lkb6c 1/1 Running 0 12s 10.244.1.2 kbs02
nginx-698ff786b7-vmd4m 1/1 Running 0 12s 10.244.2.2 kbs03
[root@kbs01 ~]# kubectl get service -o wide
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
kubernetes ClusterIP 10.96.0.1 443/TCP 26d
nginx-svc NodePort 10.97.15.203 80:31234/TCP 38s name=nginx
访问网页验证:
[root@kbs01 ~]# curl 192.168.226.10:31234
nginx
最后
以上就是愉快项链为你收集整理的以yaml文件的方式运行nginx服务的全部内容,希望文章能够帮你解决以yaml文件的方式运行nginx服务所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复