Binary
Binary

Reputation: 81

Kubernetes node port can't expose successfully

I installed kubernetes cluster on my 3 virtualbox vms. 3 vms all run Ubuntu14.04 with ufw disabled. Kubernetes versin is 1.6. Here is my config files for creating pod and service.

Pod pod.yaml:

apiVersion: v1
kind: ReplicationController
metadata:
  name: frontend
  labels:
    name: frontend
spec:
  replicas: 3
  selector:
    name: frontend
  template:
    metadata:
      labels:
        name: frontend
    spec:
      imagePullSecrets:
        - name: regsecret
      containers:
      - name: frontend
        image: hub.allinmoney.com/kubeguide/guestbook-php-frontend
        env:
        - name: GET_HOSTS_FROM
          value: env
        ports:
        - containerPort: 80

Service service.yaml:

apiVersion: v1
kind: Service
metadata:
  name: frontend
  labels:
    name: frontend
spec:
  type: NodePort
  ports:
    - port: 80
      targetPort: 31000
      nodePort: 31000
  selector:
    name: frontend

I create service with type NodePort. When I run command kubectl create -f service.yaml, it outputs like below and I can't find the exposed port 31000 in any kube nodes:

You have exposed your service on an external port on all nodes in your
cluster.  If you want to expose this service to the external internet, you may
need to set up firewall rules for the service port(s) (tcp:31000) to serve traffic.

See http://releases.k8s.io/release-1.3/docs/user-guide/services-firewalls.md for more details.

Could anyone tell how to solve this or give me any tips?

Upvotes: 0

Views: 1480

Answers (1)

JazzCat
JazzCat

Reputation: 4583

As it says in the error message you need to set up firewall rules for your nodes to accept traffic on the node ports (default: 30000-32767).

Firewall rule example

Name: [firewall-rule-name]
Targets: [node-target-name, node-target2-name]
Source filters: IP ranges: 0.0.0.0/0
Protocols / ports: tcp:80,443,30000-32767   
Action: Allow
Priority: 1000
Network: default

Your targetPort is also incorrect it needs to point to the corresponding port in the Pod (Port 80).

Upvotes: 2

Related Questions