Can i use k8s ingress services with external IP without set loadbalancer

3/31/2019

I started working with kubernetes few months ago, i create services and replicaset for differents backends applications.

Now i want use ingress service to access my differents applications from external with my domain name. As it's not in production yet and i use just on node i don't want use loadbalancer.

It is possible to set Service with NodePort and attach it to an Ingress without use loadbalancer?

This is my configuration:

kind: Service
metadata:
  name: nginx-replicaset-service
  labels:
    app: nginx-demo
spec:
  externalIPs:
    - XXX.XXX.XXX.XXX
  selector:
    app: nginx-replica
  type: NodePort
  ports:
    - name: http
      port: 80
kind: Ingress
metadata:
  name: my-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
spec:
  rules:
    - host: www.mydomain.com
      http:
        paths:
          - path: /
            backend:
              serviceName: nginx-replicaset-service
              servicePort: 80
    - host: test.mydomain.com
      http:
        paths:
          - path: /test
            backend:
              serviceName: other-service
              servicePort: 80

When i check the ingress information on my cluster i have the following:

NAME         HOSTS                                   ADDRESS   PORTS   AGE
my-ingress   www.mydomain.com,test.mydomain.com                80      4d22h

Address always empty

-- Lionel Piroche
kubernetes
kubernetes-ingress

3 Answers

3/31/2019

Not directly, or at least it would be awkward. NodePort services are limited to a range of high ports for security reasons so this would require http://externalip:43210 or whatever port it picked. The more common way to not use a LoadBalancer is to deploy the ingress controller using a DaemonSet and hostNetwork mode so it can listen on 80 and 443. This still leaves the issue of getting the IP(s) to a user though. For development purposes, you can just pick any of the IPs for your nodes and use that. For prod, it's harder which is why it's not generally recommended.

-- coderanger
Source: StackOverflow

4/1/2019

Yes you can but you shouldn't specify NodePort with ExternalIPs. With ExternalIPs, you can specify a port directly like this :

kind: Service
metadata:
  name: nginx-replicaset-service
  labels:
    app: nginx-demo
spec:
  externalIPs:
    - XXX.XXX.XXX.XXX
  selector:
    app: nginx-replica
  ports:
    - name: http
      port: 80

It will mean that you can access the service with XXX.XXX.XXX.XXX:80

It is a normal thing that you don't see any address when describing your ingress, ingress will only contains what you specified in the ingress.yaml : you only used the hostnames in your ingress.

If you do a "kubectl get svc" you will see your service with the externalIPs.

Also for your ingress to work it means www.domain.com and test.domain.com need to point to XXX.XXX.XXX.XXX.

-- S. Schenkel
Source: StackOverflow

4/1/2019

If your cluster is running on GCP or GKE you can

1) create a global IP address

gcloud compute addresses create ingress-static-ip --global

2) set the kubernetes.io/ingress.global-static-ip-name annotation on the Ingress config

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: my-ingress
  annotations:
    kubernetes.io/ingress.global-static-ip-name: ingress-static-ip
  labels:
    app: nginx-replica

3) And a service

apiVersion: v1
kind: Service
metadata:
  name: nginx-replicaset-service
  labels:
    app: nginx-demo
spec:
  selector:
    app: nginx-replica
  type: NodePort
  ports:
    - name: http
      port: 80

https://cloud.google.com/kubernetes-engine/docs/tutorials/configuring-domain-name-static-ip

-- A_Suh
Source: StackOverflow