error instantiating load balancer: service is not of type NodePort and target-type is instance

1/22/2019

I have a simple node api service, mongo service and load balancer.

I am trying to deploy my application using kubernetes I get the following error when i run the command.

- kubectl describe ing -n my-service

Warning ERROR 5s (x2 over 8s) aws-alb-ingress-controller error instantiating load balancer: my-service-api service is not of type NodePort and target-type is instance

kind: Namespace
apiVersion: v1
metadata:
  name: my-service
  labels:
    name: my-service
---
#MongoDB
apiVersion: v1
kind: Service
metadata:
  name: mongo
  namespace: my-service
  labels:
    run: mongo
spec:
  ports:
  - port: 27017
    targetPort: 27017
    protocol: TCP
  selector:
    run: mongo
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: mongo
  namespace: my-service
spec:
  template:
    metadata:
      labels:
        run: mongo
    spec:
      containers:
      - name: mongo
        image: mongo
        ports:
        - containerPort: 27017
---
apiVersion: v1
kind: Service
metadata:
  name: my-service-api
  namespace: my-service
  labels:
    app: my-service-api
spec:
  selector:
    app: my-service-api
  ports:
  - port: 3002
    protocol: TCP
    nodePort: 30002
  type: LoadBalancer
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: my-service-api-deployment
  namespace: my-service
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: my-service-api
    spec:
      containers:
      - name: my-service-api
        image: <removed>
        imagePullPolicy: Always
        env: <removed>
        ports:
        - containerPort: 3002
      imagePullSecrets:
      - name: regcred
---
#LoadBalancer
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: my-service-api
  namespace: my-service
  annotations:
    kubernetes.io/ingress.class: alb
    alb.ingress.kubernetes.io/scheme: internet-facing
    alb.ingress.kubernetes.io/target-type: instance
    alb.ingress.kubernetes.io/tags: Name=my-service-api,Owner=devops,Project=my-service,Stage=development
spec:
  rules:
    - host: <removed>
      http:
        paths:
          - path: /
            backend:
              serviceName: my-service-api
              servicePort: 3002

Can someone tell me what i am doing wrong here, thank you.

-- Kay
kubernetes
kubernetes-ingress

1 Answer

1/22/2019

It seems that your my-service-api service type is "LoadBalancer", and you need to use "NodePort" in order to use instance for alb.ingress.kubernetes.io/target-type:

May be this closed github issue can be useful for you

-- coolinuxoid
Source: StackOverflow