# NAMESPACE CONFIGURATION
apiVersion: v1
kind: Namespace
metadata:
  name: "{{namespace}}"
  labels:
    project: example
    owner: topgroup
    type: prerelease
---
# INGRESS CONFIGURATION
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: example-ingress
  namespace: "{{namespace}}"
  labels:
    project: example
    owner: topgroup
    type: prerelease
  annotations:
    kubernetes.io/ingress.class: nginx
    cert-manager.io/cluster-issuer: letsencrypt-prod
    # nginx.ingress.kubernetes.io/proxy-body-size: 50m
    # nginx.ingress.kubernetes.io/from-to-www-redirect: "true"
spec:
  tls:
    - hosts:
        - example.com
      secretName: prod-secret-example-com # this must be unique
    - hosts:
        - www.example.com
      secretName: prod-secret-www-example-com # this must be unique
  rules:
    - host: example.com
      http:
        paths:
          - path: /
            backend:
              serviceName: example-svc
              servicePort: 80
    - host: www.example.com
      http:
        paths:
          - path: /
            backend:
              serviceName: example-svc
              servicePort: 80
---
# SERVICE CONFIGURATION
apiVersion: v1
kind: Service
metadata:
  name: example-svc
  namespace: "{{namespace}}"
  labels:
    app: example
    # project label
    project: example
    owner: topgroup
    type: prerelease
spec:
  # type: NodePort
  ports:
    - port: 80
      targetPort: 80
  selector:
    app: example
---
# POD DEPLOYMENT CONFIGURATION
apiVersion: apps/v1
kind: Deployment
metadata:
  name: example
  namespace: "{{namespace}}"
  labels:
    project: example
    owner: topgroup
    type: prerelease
spec:
  replicas: 2
  selector:
    matchLabels:
      app: example
  template:
    metadata:
      labels:
        app: example
        # project label
        project: example
        owner: topgroup
        type: prerelease
    spec:
      containers:
        - name: example
          image: "{{image_name}}"
          ports:
            - containerPort: 80
          # resource quota
          resources:
            requests:
              cpu: 100m
              memory: 128Mi
            limits:
              cpu: 300m
              memory: 512Mi
          # ==================================
          # NEED TO BE CONFIGURED BY DEVELOPER
          # ==================================
          env:
            - name: NEXT_PUBLIC_ENV
              value: production
            - name: NEXT_PUBLIC_BASE_PATH
              value: example
            - name: NEXT_PUBLIC_BASE_URL
              value: "https://example.com"
            - name: NEXT_PUBLIC_API_BASE_PATH
              value: "https://api.example.com"
            - name: NEXT_PUBLIC_CDN_BASE_PATH
              value: >-
                https://google-cdn.digitop.vn/example/prod
            - name: IRON_SESSION_SECRET
              value: "SHPfrs9nuSdutexampleAw2mn8trxCVG93YVGVR"
          # ==================================
