I am trying to learn kubernetes. I can deploy containers.
How can we publish/show container through web browser?
I think we can create nodePort through service.
How can we do this?
Thank you for helping me.
I am trying to learn kubernetes. I can deploy containers.
How can we publish/show container through web browser?
I think we can create nodePort through service.
How can we do this?
Thank you for helping me.
2
Answers
Try using the below manifest to deploy a sample nginx application in Kubernetes(using a LoadBlancer IP type). I have used Minikube so the way of accessing the application would be different. This is one way of accessing the application there are other ways 1.Using Nodeport 2. Using Ingress
Deployment.yaml
Service.yml
Once these two files are created apply them using the below command
Accessing the application on K8s provided by cloud providers
If you are using kubernetes provided by some cloud provider then you will need to access the application from the
LoadBalancer IP
. This could be found by using the below command(I have deployed the application on dev namespace):This should list a service called
nginx-service
and there will be an External IP for this service you have to access the application using that External IP.Accessing application on Minikube
In Minikube if you want to access the application use the below command:
To understand more about services refer : Types of service in Kubernetes
Define service type as NodePort. This makes the service accessible on a static port on each Node in the cluster. This means that the service can handle requests that originate from outside the cluster.
sample is given below
You can also define service type as LoadBalancer if you are hosting your apps in Cloud. The service becomes accessible externally through a cloud provider’s load balancer functionality. GCP, AWS, Azure, and OpenStack offer this functionality. The cloud provider will create a load balancer, which then automatically routes requests to your Kubernetes Service.