如何通过命令行执行此部署

时间:2016-05-05 21:53:40

标签: kubernetes google-kubernetes-engine

我可以像这样进行部署,但不能通过命令行进行部署。

http://f.cl.ly/items/2V293w3F1k1d1g0a1j3j/Screen%20Shot%202016-05-05%20at%2011.48.38%20AM.png

我正在考虑这样做

kubectl create -f kubernetes-rc.json
{
  "kind": "ReplicationController",
  "apiVersion": "v1",
  "metadata": {
    "name": "foo-frontend-rc",
    "labels": {
      "www": true
    },
    "namespace": "foo"
  },
  "spec": {
    "replicas": 1,
    "template": {
      "metadata": {
        "labels": {
          "app": "foo-frontend"
        }
      },
      "spec": {
        "containers": [
          {
            "name": "foo-frontend",
            "image": "gcr.io/atomic-griffin-130023/foo-frontend:b3fc862",
            "ports": [
              {
                "containerPort": 3009,
                "protocol": "TCP"
              }
            ],
            "imagePullPolicy": "IfNotPresent"
          }
        ],
        "restartPolicy": "Always",
        "dnsPolicy": "ClusterFirst"
      }
    }
  }
}

kubectl create -f kubernetes-service.json
{
  "kind": "Service",
  "apiVersion": "v1",
  "metadata": {
    "name": "foo-frontend-service"
  },
  "spec": {
    "selector": {
      "app": "foo-frontend-rc"
    },
    "ports": [
      {
        "protocol": "TCP",
        "port": 80,
        "targetPort": 3009
      }
    ]
  }
}

无济于事。它会创建rc,但不会在外部公开服务。

1 个答案:

答案 0 :(得分:1)

您服务的选择器错误。它应该从pod模板中选择一个标签,而不是RC本身的标签。

如果您在服务中更改以下内容:

"selector": {
  "app": "foo-frontend-rc"
},

为:

"selector": {
  "app": "foo-frontend"
},

它应该修复它。

更新

将服务定义更改为

{
  "kind": "Service",
  "apiVersion": "v1",
  "metadata": {
    "name": "foo-frontend-service"
  },
  "spec": {
    "selector": {
      "app": "foo-frontend"
    },
    "ports": [
      {
        "protocol": "TCP",
        "port": 80,
        "targetPort": 3009,
        "nodePort": 30009
      }
    ],
    "type": "LoadBalancer"
  }
}