k8s安装之nginx.yaml

这里两个nginx。一个是用来测试最简单的集群的。

另一个是用来作grafana,prometheus,dashboard前端安全展示的。

简单版

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      name: nginx
  template:
    metadata:
      labels:
        name: nginx
    spec:
      containers:
        - name: nginx
          image: harbor.xxx.cn/official_hub/nginx:1.13-alpine
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-service-nodeport
spec:
  ports:
    - port: 80
      targetPort: 80
      protocol: TCP
  type: NodePort
  selector:
    name: nginx

前端安全版:

---
apiVersion: v1
kind: ConfigMap
metadata:
  name: proxy-nginx
  namespace: kube-system
data:
  default.conf: |-
    upstream prometheus {
        server prometheus:9090;
    }
    upstream grafana {
        server monitoring-grafana:80;
    }
    upstream dashboard {
        server 1.2.3.4:32766;
    }
    server {
        listen       80;
        server_name  localhost;


        location / {
            root   /usr/share/nginx/html;
            index  index.html index.htm;
        }

        location /check {
            default_type text/plain;
            return 200 "serving is ok!";
        }

        location /status {
            stub_status on;
            access_log off;
        }
        
        location  /prometheus {
            proxy_pass http://prometheus;
            proxy_set_header   Host $host;
        }
     
        location /grafana {
            proxy_pass http://grafana;
            rewrite  ^/grafana/(.*)  /$1 break;
            proxy_set_header   Host $host;
        }
   
        location /dashboard {
            auth_basic            "Password please";
            auth_basic_user_file  /etc/nginx/conf.d/nginx_passwd;
            proxy_pass  http://dashboard;
            rewrite  ^/dashboard/(.*)  /$1 break;
            proxy_set_header   Host $host;
        }
        # redirect server error pages to the static page /50x.html
        # chengang from k8s config map file
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }

    }
  nginx_passwd: |-
    admin:xxxxxxxxxxxxxxxxxxxxxxxxx
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: proxy-nginx
  namespace: kube-system
spec:
  replicas: 1
  template:
    metadata:
      labels:
        k8s-app: proxy-nginx
    spec:
      containers:
      - name: nginx
        image: harbor.xxx.cn/official_hub/nginx:1.13-alpine
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 80
          protocol: TCP
        volumeMounts:
        - name: nginx-conf
          mountPath: /etc/nginx/conf.d
      volumes:
      - name: nginx-conf
        configMap:
          name: proxy-nginx
      nodeSelector:
        node-role.kubernetes.io/master: ""
      tolerations:
      - key: "node-role.kubernetes.io/master"
        effect: "NoSchedule"
---
apiVersion: v1
kind: Service
metadata:
  name: proxy-nginx
  namespace: kube-system
spec:
  type: NodePort
  ports:
  - port: 80
    targetPort: 80
    nodePort: 32767
  selector:
    k8s-app: proxy-nginx

猜你喜欢

转载自www.cnblogs.com/aguncn/p/10904902.html