如何在kubernetes 1.0中的节点中公开服务?

时间:2015-08-19 14:09:07

标签: kubernetes

我创建了一个docker本地安装的kubernetes,我能够创建副本和服务,如下所示(这来自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

和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

根据我的理解,我应该能够从节点中的端口30000访问服务,但我得到的只是一个空响应。有什么帮助吗?

1 个答案:

答案 0 :(得分:0)

如果您以非root用户身份运行kubernetes,则可能需要检查端口范围是否允许非root用户打开端口。

从未尝试过这种方法,但另一种方法是,您可以通过复制控制器在节点上打开特定容器的端口,方法是在hostPort: 30000下面添加- containerPort: 80