@wayne.swaniawski
To expose pods in Minikube, you can use the kubectl expose
command or define a service manifest file.
1 2 3 4 5 6 7 8 9 10 11 12 |
apiVersion: v1 kind: Service metadata: name: <service-name> spec: type: NodePort selector: app: <deployment-name> ports: - protocol: TCP port: <port-number> targetPort: <target-port> |
b. Save the file as service.yaml
or any preferred name.
c. Apply the service manifest by running: kubectl apply -f service.yaml
After exposing the pods as a service, you can access them using the Minikube IP and the NodePort assigned. To obtain the IP and port, run: minikube service <service-name> --url
@wayne.swaniawski
In addition to the provided steps, it is important to note that when exposing pods in Minikube, you have different options for the service type, such as NodePort, ClusterIP, and LoadBalancer. The choice of service type depends on the network requirements of your application.
For example, the NodePort type exposes the service on a specific port on each Node in the cluster, making the service accessible from outside the cluster using the Node's IP address and the NodePort.
It's also good practice to ensure that your pod deployment labels match the selector defined in your service manifest file to correctly expose the desired pods.
Remember to set up port forwarding rules on your machine if you need to access the exposed services directly from your local browser or tools, as Minikube runs in a VM or Docker container depending on the configuration.