apiVersion: v1
kind: Service
metadata:
  name: nginx-ingress
spec:
  selector:
    app: nginx
  ports:
  - port: 8082
    targetPort: 80
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: nginx-ingress
spec:
  rules:
    - host: nginx-demo.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service: 
                name: nginx-service
                port: 
                  number: 8082
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: todo-api
spec:
  replicas: 2
  selector:
    matchLabels:
      app: todo-api
  template:
    metadata:
      name: todo-api-pod
      labels:
        app: todo-api
    spec:
      containers:
        - name: todo-api
          image: pavanelthepu/todo-api:1.0.2
          ports:
            - containerPort: 8082
          env:
            - name: "spring.data.mongodb.uri"
              value: "mongodb+srv://root:321654@cluster0.p9jg2"
---
apiVersion: v1
kind: Service
metadata:
  name: todo-api-service
spec:
  selector:
    app: todo-api
  ports:
    - name: http
      protocol: TCP
      port: 8080
      targetPort: 8082
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: todo-ui
spec:
  replicas: 2
  selector:
    matchLabels:
      app: todo-ui
  template:
    metadata:
      name: todo-ui-pod
      labels:
        app: todo-ui
    spec:
      containers:
        - name: todo-ui
          image: pavanelthepu/todo-ui:1.0.2
          ports:
            - containerPort: 80
          env:
            - name: "REACT_APP_BACKEND_SERVER_URL"
              value: "http://todo.com/api"
---
apiVersion: v1
kind: Service
metadata:
  name: todo-ui-service
spec:
  selector:
    app: todo-ui
  ports:
    - name: http
      port: 3001
      targetPort: 80
---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: todo-ingress-path-based
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  rules:
  - host: todo.com
    http:
      paths:
      - path: /(.*)
        pathType: Prefix
        backend:
          service:
            name: todo-ui-service
            port:
              number: 3001
      - path: /api/(.*)
        pathType: Prefix
        backend:
          service:
            name: todo-api-service
            port:
              number: 8080
---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: todo-ingress-host-based
spec:
  rules:
  - host: todo-ui.com
    http:
      paths:
        - path: /
          pathType: Prefix
          backend:
            service:
              name: todo-ui-service
              port:
                number: 3001
  - host: todo-api.com
    http:
      paths:
        - path: /
          pathType: Prefix
          backend:
            service:
              name: todo-api-service
              port:
                number: 8080
---
# generate a SSL/TLS Certificates - [$ openssl req -x509 -newkey rsa:4096 -sha256 -nodes -keyout tls.key -out tls.crt -subj "/CN=nginx-demo.com" -days 365]

# create a Secret - [$ kubectl create secret tls nginx-demo-com-tls --cert tls.crt --key tls.key]
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: nginx-ingress
spec:
  tls:
    - secretName: nginx-demo-com-tls
      hosts:
        - "nginx-demo.com"
  rules:
    - host: nginx-demo.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service: 
                name: nginx-service
                port: 
                  number: 8082
