title: How to expose a Ingress for external access in Kubernetes?
body: <p>I have a kubernetes cluster on a private network(private server, not aws or google cloud) and I created a Service to be able to access, however, I need to be able to access from outside the cluster and for this I created an Ingress and added ingress-nginx in the cluster.</p>
  
  <p>This is the YAML I'm using after making several attempts:</p>
  
  <pre><code>apiVersion: extensions/v1beta1
  kind: Ingress
  metadata:
    name: demo-ingress
    annotations:
      kubernetes.io/ingress.class: "nginx"
      nginx.ingress.kubernetes.io/ssl-redirect: "false"
  spec:
    rules:
    - host: k8s.local
      http:
        paths:
        - path: /
          backend:
            serviceName: nginx
            servicePort: 80
  ---
  apiVersion: v1
  kind: Service
  metadata:
    name: nginx
  spec:
    type: ClusterIP
    selector:
      name: nginx
    ports:
    - port: 80
      targetPort: 80
      protocol: TCP
    # selector:
      # app: nginx
  ---
  apiVersion: extensions/v1beta1
  kind: Deployment
  metadata:
    name: nginx
  spec:
    replicas: 1
    template:
      metadata:
        labels:
          app: nginx
      spec:
        containers:
        - name: echoserver
          image: nginx
          ports:
          - containerPort: 80
  </code></pre>
  
  <p>I ran yaml like this: <strong>kubectl create -f file.yaml</strong></p>
  
  <p>In the /etc/hosts file I added <strong>k8s.local</strong> to the ip of the master server.</p>
  
  <p>When trying the command in or out of the master server a "Connection refused" message appears:
  <strong>$ curl <a href="http://172.16.0.18:80/" rel="noreferrer">http://172.16.0.18:80/</a> -H 'Host: k8s.local'</strong></p>
  
  <p>I do not know if it's important, but I'm using Flannel in the cluster.</p>
  
  <p>My idea is just to create a 'hello world' and expose it out of the cluster!</p>
  
  <p>Do I need to change anything in the configuration to allow this access?</p>
  
  <hr>
  
  <p>YAML file edited:</p>
  
  <pre><code>    apiVersion: extensions/v1beta1
  kind: Ingress
  metadata:
    name: demo-ingress
    annotations:
      kubernetes.io/ingress.class: "nginx"
      nginx.ingress.kubernetes.io/ssl-redirect: "false"
      # nginx.ingress.kubernetes.io/rewrite-target: /
  spec:
    rules:
    - host: k8s.local
      http:
        paths:
        - path: /teste
          backend:
            serviceName: nginx
            servicePort: 80
  ---
  apiVersion: v1
  kind: Service
  metadata:
    name: nginx
  spec:
    type: LoadBalancer # NodePort
    selector:
      app: nginx
    ports:
    - port: 80
      targetPort: 80
      protocol: TCP
  ---
  apiVersion: extensions/v1beta1
  kind: Deployment
  metadata:
    name: nginx
  spec:
    replicas: 1
    template:
      metadata:
        labels:
          app: nginx
      spec:
        containers:
        - name: echoserver
          image: nginx
          ports:
          - containerPort: 80
  </code></pre>