To expose a service in Minikube, you can follow these steps:
- Start Minikube:
- 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
- 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.
- 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.