Kubernetes question: I seem to not be able to access my service from my local machine (pods are running on minikube), when I run the command kubectl describe pod pod-id
I see these two lines but I don't know if they have anything to do with not being able to access the deployment:
Port: 8888/TCP
Host Port: 0/TCP
But when I run
kubectl get services
I see no External-IP
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
ci-master NodePort 10.103.13.96 <none> 8888:31388/TCP 1m
Here's my service.yaml
file:
apiVersion: v1
kind: Service
metadata:
name: ci-master
labels:
app: ci
tier: fullstack
role: master
spec:
type: NodePort
ports:
- port: 8888
targetPort: 8888
selector:
app: ci
role: master
tier: fullstack
And the part that I think should be relevant in my deployment.yaml
:
spec:
template:
spec:
containers:
- name: ci
image: rand/image-one:latest
ports:
- containerPort: 8888
When I try to access the service with minikube service ci-master
I get this message indefinitely: Waiting, endpoint for service is not ready yet...
The service is serving, when I try kubectl describe pod pod-id
I see this line at the bottom:
Type Reason Age From Message
Normal Started 24m kubelet, minikube Started container
What am I missing?
With this configuration, you service is running on port 8888, and it is mapped to port 31388 of the node. So you can hit it on port 8888 from within the cluster, and on port 31388 from outside world.
About services, targerPort
is the port the requests are sent to, so it is the containerPort
of your deployment. These two ALWAYS need to match...
...And port
is the service port. So your service is available on 10.103.13.96:8888.
What I was missing was the Service Type, if I want something accessible from the external world, I had to pick LoadBalancer
.
So this simple change fixed it:
spec:
type: LoadBalancer
ports:
- port: 8888
targetPort: 8888
Now I finally have:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
ci-master LoadBalancer 10.15.243.32 35.211.12.22 80:32463/TCP 1m