How can we access ubuntu container image from outside the host?

3/5/2019

We access the container through cluster IP and even we deploy web application containers can be accessed.The issue with how can we access container from outside the host. Tried with giving external IP to containers.

-- amit potdar
containers
docker
kubernetes

2 Answers

3/5/2019

The best approach would be to expose your pods with ClusterIP type services, and then use an Ingress resource along with Ingress Controller to expose HTTP and/or HTTPS routes so you can access your app outside of the cluster.

For testing purposes it's ok to use NodePort or LoadBalancer type services. Whether you are running on your own infrastructure or using a managed solution, you can use NodePort, while using LoadBalancer requires cloud provider's load balancer.

Source: Official docs

-- shmandrija
Source: StackOverflow

3/5/2019

You can create a service and bind it to a node port, from outside your cluster if you try to access that service using node_ip:port.

apiVersion: v1
kind: Service
metadata:
  name: api-server
spec:
  ports:
  - port: 80
    name: http
    targetPort: api-http
    nodePort: 30004
  - port: 443
    name: https
    targetPort: api-http
  type: LoadBalancer
  selector:
    run: api-server

if you do kubectl get service you can get the external ip.

-- sadaf2605
Source: StackOverflow