0
votes

I created a docker local install of kubernetes and I was able to create the replicas and services as bellow (this is from kubernetes 201):

rc:

apiVersion: v1
kind: ReplicationController
metadata:
  name: nginx-controller
spec:
  replicas: 2
  # selector identifies the set of Pods that this
  # replication controller is responsible for managing
  selector:
    app: nginx
  # podTemplate defines the 'cookie cutter' used for creating
  # new pods when necessary
  template:
    metadata:
      labels:
        # Important: these labels need to match the selector above
        # The api server enforces this constraint.
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80

and the service.yaml:

apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  ports:
  - port: 8000 # the port that this service should serve on
    # the container on each pod to connect to, can be a name
    # (e.g. 'www') or a number (e.g. 80)
    targetPort: 80
    protocol: TCP
    nodePort: 30000
  type: LoadBalancer
  # just like the selector in the replication controller,
  # but this time it identifies the set of pods to load balance
  # traffic to.
  selector:
    app: nginx

From my understanding, I should be able to access the service from port 30000 in the node, but all I get is an empty response. Any help?

1

1 Answers

0
votes

If you are running kubernetes as non-root, you may need to check the port range if non-root are allowed to open the port.

Never tried this but another way you can open the port on the nodes for a particular container is through the replicationcontroller by adding hostPort: 30000 below the - containerPort: 80