Search code examples
kuberneteskubernetes-go-client

How can I generate External IP when creating an ingress that uses nginx controller in kubernetes


apiVersion: extensions/v1beta1
kind: Ingress 
metadata:
  name: helloworld-rules
spec:
  rules:
  - host: helloworld-v1.example.com
http:
  paths:
  - path: /
    backend:
      serviceName: helloworld-v1
      servicePort: 80
  - host: helloworld-v2.example.com
http:
  paths:
  - path: /
    backend:
           serviceName: helloworld-v2
           servicePort: 80

I'm making kubernetes cluster and I will apply that cloudPlatform Isolated(not aws or google). When creating an ingress for service I can choose host url but that is not exist anywhere(that address is not registrated something like DNS server) So I can't access that url. Visiting this IP just gives a 404. how can I get or configure URL that can access external browser :(...


Solution

  • It depends on how you configure your nginx controller.

    You should have a Service configured which is the entry point when accessing from outside see the docs https://kubernetes.io/docs/concepts/services-networking/ingress/#what-is-ingress.

    So basically you have a Service that points to the ingress controller and this will redirect the traffic to your pods based on Ingress Objects.

    Ingress -> Services -> Pods

    Since you don't run on aws or google You would have to use externalIp or NodePort and configure the service accordingly

    kind: Service
    apiVersion: v1
    metadata:
      name: ingress-nginx
      namespace: ingress-nginx
      labels:
        app: ingress-nginx
    spec:
      selector:
        app: ingress-nginx
      ports:
      - name: http
        port: 80
        targetPort: http
      - name: https
        port: 443
        targetPort: http
      externalIPs:
      - 80.11.12.10
    

    And DNS needs to be managed with whatever you have for your domains in order to resolve, or for locally testing you can just edit your /etc/hostnames

    Basically in AWS or Google you just create a service with type: LoadBalancer and point your dns records to the balancer address (CNAME for aws and the IP for google)