<p>I'm trying to deploy two nodejs applications as two separate containers using Kubernetes, a defined service and an ingress with a static ip and a ssl certificate</p>

<p>I would like to deploy these micro-services using Kubernetes Engine of the GCP. I've added the second micro-service later than the other one. With only one container into the pod, everything works good.
I've defined three yaml files: deployment.yaml, service.yaml, ingress.yaml. </p>

<p>deployment.yaml</p>

<pre><code>apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: qa-chatbot-backend-deployment
spec:
  selector:
    matchLabels:
      app: service-backend1
  replicas: 1
  template:
    metadata:
      labels:
        app: service-backend1
    spec:
      containers:
        - name: serice-backend1
          image: gcr.io/project-id/serice-backend1:v1.0.1
          imagePullPolicy: Always
          command: ["npm", "start"]
          livenessProbe:
            httpGet:
              path: /
              port: 8081
              scheme: HTTP
            initialDelaySeconds: 30
            timeoutSeconds: 25
            periodSeconds: 30
            successThreshold: 1
            failureThreshold: 2
          readinessProbe:
            httpGet:
              path: /
              port: 8081
              scheme: HTTP
            initialDelaySeconds: 30
            timeoutSeconds: 25
            periodSeconds: 30
            successThreshold: 1
            failureThreshold: 2
          ports:
            - name: service1-port
              containerPort: 8081
        - name: service-backend2
          image: gcr.io/project-id/serice-backend2:v1.0.1
          imagePullPolicy: Always
          command: ["npm", "start"]
          livenessProbe:
            httpGet:
              path: /api/test
              port: 8082
              scheme: HTTP
            initialDelaySeconds: 30
            timeoutSeconds: 25
            periodSeconds: 30
            successThreshold: 1
            failureThreshold: 2
          readinessProbe:
            httpGet:
              path: /api/test
              port: 8082
              scheme: HTTP
            initialDelaySeconds: 30
            timeoutSeconds: 25
            periodSeconds: 30
            successThreshold: 1
            failureThreshold: 2
          ports:
            - name: service2-port
              containerPort: 8082
</code></pre>

<p>service.yaml</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: service-kube
spec:
  type: LoadBalancer
  ports:
    - targetPort: service1-port
      port: 80
      protocol: TCP
  selector:
    app: service-backend1

</code></pre>

<p>ingress.yaml</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  labels:
    app: service-backend1
  name: ingress-kube
  annotations:
    kubernetes.io/ingress.global-static-ip-name: app-static-ip
spec:
  tls:
  - hosts:
    - custom-host.com
    secretName: custom-host-secret-name
  rules:
  - host: custom-host.com
    http:
      paths:
      - backend:
          serviceName: service-kube
          servicePort: 80

</code></pre>

<p>With this configuration, only one service is reachable, the first one</p>

<p>I've tried to add multiple ports into service.yaml</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: service-kube
spec:
  type: LoadBalancer
  ports:
    - targetPort: service1-port
      port: 80
      protocol: TCP
    - targetPort: service2-port
      port: 80
      protocol: TCP
  selector:
    app: service-backend1
</code></pre>

<p>But i receive an error.</p>

<pre><code>The Service "service-kube" is invalid: spec.ports[1]: Duplicate value: core.ServicePort{Name:"", Protocol:"TCP", Port:80, TargetPort:intstr.IntOrString{Type:0, IntVal:0, StrVal:""}, NodePort:0}
</code></pre>

<p>My goal is to expose on the domain custom-host.com two backends; one reachable on a specific path (api/*), the other one reachable to all the possible endpoints.</p>

<p>Thank you for your help</p>

d_vucin91
<p>You can't have a single service port send traffic to two different target ports. 
There must be two different ports on your service (or use two separate services).
Then you should have two <code>paths</code> in your ingress that route to the appropriate service port.</p>

<p>You need to do something like this...</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: service-kube
spec:
  type: LoadBalancer
  ports:
    - targetPort: service1-port
      port: 81
      protocol: TCP
    - targetPort: service2-port
      port: 82
      protocol: TCP
  selector:
    app: service-backend1
</code></pre>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  labels:
    app: service-backend1
  name: ingress-kube
  annotations:
    kubernetes.io/ingress.global-static-ip-name: app-static-ip
spec:
  tls:
  - hosts:
    - custom-host.com
    secretName: custom-host-secret-name
  rules:
  - host: custom-host.com
    http:
      paths:
      - backend:
          serviceName: service-kube
          servicePort: 81
        path: /api
      - backend:
          serviceName: service-kube
          servicePort: 82
        path: /
</code></pre>
