Cannot access Kubernetes service

2/6/2017

We are not able to access the nginx from outside the pod cluster. Kindly help us understand if below seems right and which port will be serving nginx. Running a curl on NodeIP:NodePort throws our company proxy access denied page. We have VM on openstack and Security Group is open.

[root@ip-10-0-0-3 pods]# kubectl get deployments NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE nginx-demo 2 2 2 2 4m

[root@ip-10-0-0-3 pods]# kubectl get pods NAME READY STATUS RESTARTS AGE nginx-demo-1947000120-6omcz 1/1 Running 0 5m nginx-demo-1947000120-exewa 1/1 Running 0 5m

Below is the Kubernetes Deployment and service file.

apiVersion: extensions/v1beta1 kind: Deployment metadata: name: nginx-demo spec: replicas: 2 selector: matchLabels: app: nginx-demo minReadySeconds: 20 template: metadata: labels: app: nginx-demo version: v0.1 spec: containers: - name: nginx-demo image: nginx imagePullPolicy: Always ports: - containerPort: 80 protocol: TCP env: - name: DEMO_ENV value: staging **---**(ignore stars) apiVersion: v1 kind: Service metadata: labels: app: nginx-demo name: nginx-demo-svc spec: ports: - port: 80 protocol: TCP name: www nodePort: 30089 selector: app: nginx-demo type: NodePort


[root@ip-10-0-0-3 pods]# kubectl describe svc Name: nginx-demo-svc Namespace: default Labels: app=nginx-demo Selector: app=nginx-demo Type: NodePort IP: 192.168.1.20 Port: www 80/TCP NodePort: www 30089/TCP Endpoints: 172.17.50.2:80,172.17.67.2:80 Session Affinity: None No events.


[root@ip-10-0-0-3 pods]# kubectl get svc NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes 10.254.0.1 <none> 443/TCP 2d nginx-demo-svc 192.168.1.20 <nodes> 80/TCP 9m


-- Amol Shinde
kubernetes
nginx

1 Answer

8/22/2017

The selector section of your service must contains all labels :

selector:
  app: nginx-demo
  version: v0.1

It's better?

-- Julien
Source: StackOverflow