nginx对K8s集群中的Service做负载均衡

2021/12/29 7:11:03

本文主要是介绍nginx对K8s集群中的Service做负载均衡,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

编写Service.yml文件

[root@master ~]# cat nginx.yml 
---
apiVersion: apps/v1
kind: Deployment
metadata: 
  name: web
spec:
  replicas: 2 
  selector: 
    matchLabels: 
      app: nginx 
  template: 
    metadata: 
      labels: 
        app: nginx
    spec: 
      volumes:
      - name: webstorage
        hostPath: 
          path: /var/www/html
      containers: 
      - name: web
        image: nginx
        imagePullPolicy: IfNotPresent
        volumeMounts: 
        - name: webstorage
          mountPath: /usr/share/nginx/html
...

---
apiVersion: v1
kind: Service
metadata: 
  name: web
spec: 
  type: NodePort
  ports: 
  - port: 80
    targetPort: 80
    protocol: TCP
    nodePort: 30000
  selector: 
    app: nginx




这篇关于nginx对K8s集群中的Service做负载均衡的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程