apiVersion: v1
kind: Service
metadata:
  name: dnc
  labels:
    app: dnc
  namespace: nextgenleads
spec:
  ports:
    - name: http-dnc
      port: 8080
      protocol: TCP
    - name: grpc-dnc
      port: 5000
      protocol: TCP
  selector:
    app: dnc
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: dnc
  namespace: nextgenleads
  labels:
    app: dnc
spec:
  replicas: 1
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: dnc
  template:
    metadata:
      labels:
        app: dnc
      name: dnc
    spec:
      enableServiceLinks: false
      containers:
        - name: dnc
          image: dnc:dev
          imagePullPolicy: Always
          env:
            - name: APP_HTTP_PORT
              value: "8080"
            - name: APP_GRPC_PORT
              value: "5000"
            - name: POSTGRESQL_HOST
              value: "postgresql.nextgenleads.svc.cluster.local"
            - name: REDIS_HOST
              value: "redis.nextgenleads.svc.cluster.local"
          ports:
            - name: grpc-app
              containerPort: 5000
            - name: http-app
              containerPort: 8080
          livenessProbe:
            exec:
              command: ["/bin/grpc_health_probe", "-addr=:5000"]
            initialDelaySeconds: 10
          readinessProbe:
            exec:
              command: ["/bin/grpc_health_probe", "-addr=:5000"]
            initialDelaySeconds: 5
---
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
  name: ngl-dnc
  namespace: istio-system
spec:
  secretName: ngl-dnc
  subject:
    organizations:
      - "NGL Dev"
  dnsNames:
    - dnc.nextgenleads.test
  issuerRef:
    name: ca-issuer
    kind: ClusterIssuer
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: dnc
  namespace: nextgenleads
spec:
  hosts:
    - dnc.nextgenleads.test
  gateways:
    - mesh
    - nextgenleads/dnc
  http:
    - name: grpc
      match:
        - port: 5000
      route:
        - destination:
            host: dnc.nextgenleads.svc.cluster.local
            port:
              number: 5000
    - name: http
      match:
        - port: 80
      route:
      - destination:
          host: dnc.nextgenleads.svc.cluster.local
          port:
            number: 8080
---
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: dnc
  namespace: nextgenleads
spec:
  selector:
    istio: ingressgateway
  servers:
    - port:
        number: 80
        name: http-client
        protocol: HTTP
      hosts:
        - dnc.nextgenleads.test
      tls:
        httpRedirect: true
    - port:
        number: 443
        name: http-api
        protocol: HTTPS
      hosts:
        - dnc.nextgenleads.test
      tls:
        mode: SIMPLE
        credentialName: ngl-dnc
        minProtocolVersion: TLSV1_2
    - port:
        number: 5000
        name: grpc-client
        protocol: HTTP2
      hosts:
        - dnc.nextgenleads.test
