Search code examples
dockerminikubeskaffold

How to fix service PORT for minikube - skaffold local environment?


Currently I am using a local environment with Skaffold + Minikube and every time I start the cluster like this:

skaffold dev -f='./skaffold-cluster.yaml' --no-prune=false --cache-artifacts=false --status-check=false

I get a bunch of services that belongs to my skaffold manifests, but each one of this services are exposed with random ports. The ip is the same because minikube have already started.

If I do: minikube service nice-service --url I will get the service with the random PORT.

I want to be able to fix this port. But I don't see if this is something that should be consider in k8s configuration / skaffold / minikube / docker ??

Typical use case: I want to access mysql from sequel pro / workbench or any tool... therefor this configurations are saved locally with a port... it would be great to not to have to change the port in this tools, to access to the minikube service of mysql...

Current setup has: Virtualbox in OS system, with minikube and skaffold. Services are being exposed as k8s service node ports.

Is it possible to Fix this port services?


Solution

  • By changing the nodePort option:

    apiVersion: v1
    kind: Service
    metadata:
      name: my-service
    spec:
      type: NodePort
      selector:
        app: MyApp
      ports:
          # By default and for convenience, the `targetPort` is set to the same value as the `port` field.
        - port: 80
          targetPort: 80
          # Optional field
          # By default and for convenience, the Kubernetes control plane will allocate a port from a range (default: 30000-32767)
          nodePort: 30007
    

    nodePort is the one exposed by minikube service my-service --url by adding this option it will not be random any more, but the port you need.