apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: nginx-ingress
  namespace: nginx-ingress
spec:
  selector:
    matchLabels:
      app: nginx-ingress
  template:
    metadata:
      labels:
        app: nginx-ingress
     #annotations:
       #prometheus.io/scrape: "true"
       #prometheus.io/port: "9113"
    spec:
      hostNetwork: true
      serviceAccountName: nginx-ingress
      containers:
      - image: magicalyak/nginx-plus:r19v1
#      - image: myregistry.example.com/nginx-plus-ingress:edge
        imagePullPolicy: IfNotPresent
        name: nginx-plus-ingress
        ports:
        - name: http
          containerPort: 80
          hostPort: 80
        - name: https
          containerPort: 443
          hostPort: 443
       #- name: prometheus
         #containerPort: 9113
        securityContext:
          allowPrivilegeEscalation: true
          runAsUser: 101 #nginx
          capabilities:
            drop:
            - ALL
            add:
            - NET_BIND_SERVICE
        env:
        - name: POD_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        - name: POD_NAME
          valueFrom:
            fieldRef:
              fieldPath: metadata.name
        - name: POD_IP
          valueFrom:
            fieldRef:
              fieldPath: status.podIP
        command:
          - /nginx-ingress.wrapper ### custom wrapper script to set Pod IP
        args:
          - -nginx-plus
          - -nginx-configmaps=$(POD_NAMESPACE)/nginx-config
          - -default-server-tls-secret=$(POD_NAMESPACE)/default-server-secret
         #- -v=3 # Enables extensive logging. Useful for troubleshooting.
         #- -report-ingress-status
         #- -external-service=nginx-ingress
          - -enable-leader-election
         #- -enable-prometheus-metrics
          - -enable-custom-resources
#          - -nginx-status-allow-cidrs=127.0.0.1
          - -nginx-status-allow-cidrs=0.0.0.0/0 #Wide open for status page DEMO ONLY          
          #- -nginx-debug
        ### custom volume mounts
        volumeMounts:
          - name: nginx-to-as3
            mountPath: /etc/nginx/conf.d/nginx_to_as3.js
            subPath: nginx_to_as3.js
          - name: localhost-conf
            mountPath: /etc/nginx/conf.d/localhost.conf.template
            subPath: localhost.conf.template
          - name: nginx-ingress-wrapper
            mountPath: /nginx-ingress.wrapper
            subPath: nginx-ingress.wrapper
      volumes:
        - name: nginx-to-as3
          configMap:
            name: nginx-to-as3
        - name: localhost-conf
          configMap:
            name: localhost.conf.template
        - name: nginx-ingress-wrapper
          configMap:
            name: nginx-ingress.wrapper
            defaultMode: 0755