Kubernetes services to be exposed to local machine Kubernetes services to be exposed to local machine kubernetes kubernetes

Kubernetes services to be exposed to local machine


I think you are looking for this. I had the same issue when I tried everything locally. You'll need to use --type=NodePort

For example I've created a deployment:

./cluster/kubectl.sh run my-jenkins --image=jenkins:1.651.1 --replicas=1 --port=8080 –-namespace=jenkins

I check the pod

kubectl --namespace=jenkins get podsNAME                          READY     STATUS    RESTARTS   AGEmy-jenkins-1908062973-7b44z   1/1       Running   0          24s

My deployment created a pod + replicaSet for me in the deploymentconfig.Now I want to create a service above my pod

./cluster/kubectl.sh expose rs my-jenkins-1908062973 --port=80 --target-port=8080 --type=NodePort --name=jenkins-service --namespace=jenkins

Thanks to the --type=NodePort I'm able to visit my service also locally

If you set the type field to "NodePort", the Kubernetes master will allocate a port from a flag-configured range (default: 30000-32767), and each Node will proxy that port (the same port number on every Node) into your Service. That port will be reported in your Service’s spec.ports[*].nodePort field.