DHOZEd.png

nginx-custom-config.yaml:

---
apiVersion: v1
kind: ConfigMap
metadata:
  name: custom-nginx-config
  namespace: default
data:
  default.conf: |
    upstream my-svc {
        server echo-svc.default.svc.cluster.local;
    }

    server {
        listen       80;
        server_name  localhost;

        location / {

            root   /usr/share/nginx/html;
            index  index.html index.htm;

            if ($http_user_agent ~* "iPhone|iPad" ) {
                add_header X-Vendor "Apple";
                proxy_pass  http://my-svc;
            }
            if ($http_user_agent ~ Chrome ) {
                add_header X-Vendor "OpenSource";
                proxy_pass  http://my-svc;
            }

            proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;
        }
        error_page   500 502 503 504  /50x.html;

        location = /50x.html {
            root   /usr/share/nginx/html;
        }
    }

custom-nginx-deployment.yaml:

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: custom-nginx
spec:
  selector:
    matchLabels:
      app: custom-nginx
  template:
    metadata:
      labels:
        app: custom-nginx
    spec:
      containers:
      - name: custom-nginx
        image: nginx
        volumeMounts:
        - name: custom-nginx-config
          mountPath: /etc/nginx/conf.d
        ports:
        - name: http
          containerPort: 80
        imagePullPolicy: IfNotPresent
      volumes:
        - name: custom-nginx-config
          configMap:
            name: custom-nginx-config

custom-nginx-svc.yaml:

---
apiVersion: v1
kind: Service
metadata:
  name: custom-nginx-svc
  labels:
    app: custom-nginx
spec:
  selector:
    app: custom-nginx
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
  type: LoadBalancer

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

Captcha Code