【问题标题】:How to expose my pod to the internet and get to it from the browser?如何将我的 pod 暴露在互联网上并从浏览器访问它?
【发布时间】:2016-04-14 13:07:29
【问题描述】:

首先我下载了​​ kubernetes、kubectl 并从 aws 创建了一个集群 (export KUBERNETES_PROVIDER=aws; wget -q -O - https://get.k8s.io | bash )

我在我的项目 circle.yml 中添加了一些行,以使用 circleCI 服务来构建我的图像。

为了支持 docker 我添加了:

machine:
  services:
    - docker

并创建我的图像并将其发送到我添加的工件:

deployment:
    commands:
      - docker login -e admin@comp.com -u ${ARTUSER} -p ${ARTKEY} docker-docker-local.someartifactory.com
      - sbt -DBUILD_NUMBER="${CIRCLE_BUILD_NUM}" docker:publish

之后我创建了 2 个文件夹:

我的项目(MyApp)文件夹有两个文件:

controller.yaml

apiVersion: v1
kind: ReplicationController
metadata:
  name: MyApp
  labels:
    name: MyApp
spec:
  replicas: 1
  selector:
    name: MyApp
  template:
    metadata:
      labels:
        name: MyApp
        version: 0.1.4
    spec:
      containers:
      - name: MyApp
        #this is the image artifactory
        image: docker-docker-release.someartifactory.com/MyApp:0.1.4
        ports:
        - containerPort: 9000
      imagePullSecrets:
        - name: myCompany-artifactory

service.yaml

apiVersion: v1
kind: Service
metadata:
  name: MyApp
  labels:
    name: MyApp
spec:
  # if your cluster supports it, uncomment the following to automatically create
  # an external load-balanced IP for the frontend service.
  type: LoadBalancer
  ports:
    # the port that this service should serve on
  - port: 9000
  selector:
    name: MyApp

我的工件还有另一个文件夹(种类:秘密)。

现在我创建了我的 pod:

kubectl create -f controller.yaml

现在,当我签入 kubectl get pods 时,我的 pod 正在运行。

现在,如何从浏览器访问我的 pod?我的项目是一个 play 项目,所以我想从浏览器中访问它...如何以最简单的方式公开它?

谢谢

【问题讨论】:

    标签: amazon-web-services docker cluster-computing kubernetes


    【解决方案1】:
    • Replication Controller 的唯一职责是确保在您的集群上运行具有给定配置的 pod 数量。

    • Service 是公开的(或内部)将您的 pod 暴露给系统的其他部分(或互联网)。

    您应该使用 yaml 文件 (kubectl create -f service.yaml) 创建服务,该文件将创建服务,通过标签选择器 MyApp 选择 pod 以处理文件中给定端口上的负载 (9000)。

    然后查看使用kubectl get service 注册的服务,以查看为其分配了哪个端点(ip)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-04
      • 2017-06-21
      • 1970-01-01
      • 2017-11-29
      • 1970-01-01
      • 1970-01-01
      • 2011-06-05
      相关资源
      最近更新 更多