Yiliu
Yiliu

Reputation: 21

Kubernetes, Cannot access exposed services

Kubernetes version: v1.10.3

Docker version: 17.03.2-ce

Operating system and kernel: Centos 7

Steps to Reproduce: https://kubernetes.io/docs/tasks/access-application-cluster/service-access-application-cluster/

Results:

[root@rd07 rd]# kubectl describe services example-service

Name: example-service
Namespace: default
Labels: run=load-balancer-example
Annotations:
Selector: run=load-balancer-example
Type: NodePort
IP: 10.108.214.162
Port: 9090/TCP
TargetPort: 9090/TCP
NodePort: 31105/TCP
Endpoints: 192.168.1.23:9090,192.168.1.24:9090
Session Affinity: None
External Traffic Policy: Cluster
Events:

Expected:

Expect to be able to curl the cluster ip defined in the kubernetes service

I'm not exactly sure which is the so called "public-node-ip", so I tried every related ip address, only when using the master ip as the "public-node-ip" it shows "No route to host".

I used "netstat" to check if the endpoint is listened.

I tried "https://github.com/rancher/rancher/issues/6139" to flush my iptables, and it was not working at all.

I tried "https://kubernetes.io/docs/tasks/debug-application-cluster/debug-service/", "nslookup hostnames.default" is not working.

The services seems working perfectly fine, but the services still cannot be accessed.

I'm using "calico" and the "flannel" was also tried.

I tried so many tutorials of apply services, they all cannot be accessed.

I'm new to kubernetes, plz if anyone could help me.

Upvotes: 1

Views: 2382

Answers (3)

Muthu Vijay
Muthu Vijay

Reputation: 59

Use this command:

kubectl get service

If your service "TYPE" is "NodePort" and "EXTERNAL-IP" column is "none" then you can access or curl your service from the URL: http://<localmachine_ip>:<port_no>

Port number also available in the result of the command kubectl get service in the column PORT(S). For example, if the value of PORT(S) is 1000:31918/TCP, then the port number is 31918.

If the service type is ClusterIP then you first delete the service using the command kubectl delete service <servie_name> and use the following command:

kubectl expose deployment <deployment_name> --type=NodePort --port=80

This command will start the service of TYPE = NodePort

Note: you have to expose the deployment. I assume that you are aware of deployment in K8s.

Upvotes: 0

Yiliu
Yiliu

Reputation: 21

My k8s cluster is 1 master and 1 node.
The service pod is running on the node.
So I used http://nodeip:31105, it shows "Hello Kubernetes!".
But http://masterip:31105 still not working, is it suppose to be right?
I checked the endpoint listen, 31105 is listened on master.

Upvotes: 0

chintan thakar
chintan thakar

Reputation: 1500

If you are on any public cloud you are not supposed to get public ip address at ip a command. But even though the port will be exposed to 0.0.0.0:31105

Here is the sample file you can verify for your configuration:

apiVersion: v1
kind: Service
metadata:
  labels:
    k8s-app: app-name
  name: bss
  namespace: default
spec:
  externalIPs:
  - 172.16.2.2
  - 172.16.2.3
  - 172.16.2.4
  externalTrafficPolicy: Cluster
  ports:
  - port: 9090
    protocol: TCP
    targetPort: 9090
  selector:
    k8s-app: bss
  sessionAffinity: ClientIP
  type: LoadBalancer
status:
  loadBalancer: {}

Just replace your <private-ip> at externalIPs: and do curl your public ip with your node port.

If you are using any cloud to deploy application, Also verify configuration from cloud security groups/firewall for opening port.

Hope this may help.

Thank you!

Upvotes: 1

Related Questions