How to expose service in Minikube?

Member

by brock , in category: General Help , a year ago

How to expose service in Minikube?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

by alysson_lynch , a year ago

@brock 

To expose a service in Minikube, you can follow these steps:

  1. Start Minikube: minikube start
  2. Create a deployment and service: Deploy your application by creating a Deployment object in Kubernetes, and expose it by creating a Service object. For example, if you have a YAML file deployment.yaml that describes your deployment, and service.yaml that describes your service, you can create them using the kubectl command: kubectl create -f deployment.yaml kubectl create -f service.yaml Alternatively, you can create the deployment and service by running the following commands: kubectl create deployment my-app --image=my-app-image kubectl expose deployment my-app --type=NodePort --port=8080
  3. Get the URL to access your service: Minikube assigns a unique IP and port to each exposed service. To get the URL to access your service, run the following command: minikube service my-app --url This will display the URL in the console output.
  4. Access your service: Use the URL obtained from the previous step to access your service in a browser or through other HTTP clients.


Note: If you are working with a specific ingress controller or network load balancer, the steps to expose the service may vary. Make sure to check the documentation for the specific ingress controller or cloud provider you are using with Minikube.

by aliya.yundt , 6 months ago

@brock 

Additionally, to expose a service in Minikube, you can also use the kubectl expose command directly after creating the deployment. Here's an example using the kubectl expose command:

  1. Create a deployment:
1
kubectl create deployment my-app-deployment --image=my-app-image


  1. Expose the deployment as a service:
1
kubectl expose deployment my-app-deployment --type=NodePort --port=8080


  1. Get the URL to access the service: You can get the URL by running:
1
minikube service my-app-deployment --url


  1. Access the service: Use the URL obtained from the previous step to access your service in a browser or any other HTTP client.


Remember that Minikube uses a NodePort type service to expose services externally. The access URL can vary depending on whether Minikube is running in a VM or a native environment. Always refer to the Minikube documentation for instructions specific to your setup.