How to expose pods in Minikube?

by wayne.swaniawski , in category: General Help , a month ago

How to expose pods in Minikube?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by ari.olson , a month ago

@wayne.swaniawski 

To expose pods in Minikube, you can use the kubectl expose command or define a service manifest file.

  1. Using kubectl expose command: a. Open a terminal window and start the Minikube cluster by running: minikube start b. Verify that the cluster is running by executing: kubectl cluster-info c. Deploy your application by creating a deployment using: kubectl create deployment
  2. Using the service manifest file: a. Create a YAML file with the following contents:
 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>


  • : Provide a name for your service.
  • : The name of your deployment.
  • : The port number on which your application should listen.
  • : The port number on which your application is actually running.


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