【问题标题】:Kubernetes Service does not get its external IP addressKubernetes Service 没有得到它的外部 IP 地址
【发布时间】:2016-12-19 10:05:15
【问题描述】:

当我分两步(1. 复制控制器;2. 公开复制控制器)构建 Kubernetes 服务时,我公开的服务会获得一个外部 IP 地址:

initially:
    NAME         CLUSTER_IP     EXTERNAL_IP     PORT(S)   SELECTOR    AGE
    app-1        10.67.241.95                   80/TCP    app=app-1    7s

大约 30 秒后:

NAME         CLUSTER_IP     EXTERNAL_IP     PORT(S)   SELECTOR    AGE
app-1        10.67.241.95   104.155.93.79   80/TCP    app=app-1   35s

但是当我一步一步将ServiceReplicationController 提供给kubectl create -f dir_with_2_files 时,服务被创建但它没有获得外部IP:

NAME         CLUSTER_IP      EXTERNAL_IP   PORT(S)   SELECTOR    AGE
app-1        10.67.251.171   <none>        80/TCP    app=app-1   2m

External IP 下的&lt;none&gt; 让我担心。

对于我使用 JSON 文件的服务:

{                                                                                                                 
    "apiVersion": "v1",                                                                                           
    "kind": "Service",                                                                                            
    "metadata": {                                                                                                 
        "name": "app-1"                                                                                           
    },                                                                                                            
    "spec": {                                                                                                     
        "selector": {
            "app": "app-1"
        },
        "ports": [                                                                                                
            {                                                                                                     
                "port": 80,                                                                                       
                "targetPort": 8000                                                                                
            }                                                                                                     
        ]
    }                                                                                                             
}

对于 ReplicationController:

{
    "apiVersion": "v1",
    "kind": "ReplicationController",
    "metadata": {
        "name": "app-1"
    },
    "spec": {
        "replicas": 1,
        "template": {
            "metadata": {
                "labels": {
                    "app": "app-1"
                }
            },
            "spec": {
                "containers": [
                    {
                        "name": "service",
                        "image": "gcr.io/sigma-cairn-99810/service:latest",
                        "ports": [
                            {
                                "containerPort": 8000
                            }
                        ]
                    }
                ]
            }
        }
    }
}

为了手动公开服务,我使用以下命令:

kubectl expose rc app-1 --port 80 --target-port=8000 --type="LoadBalancer"

【问题讨论】:

    标签: kubernetes


    【解决方案1】:

    如果您不指定服务的类型,则默认为 ClusterIP。如果你想要expose 的等价物,你必须:

    1. 确保您的服务通过匹配的标签选择器从 RC 中选择 pod
    2. 制作服务type=LoadBalancer

    【讨论】:

    • 确实type=LoadBalancer 不见了。谢谢!
    猜你喜欢
    • 2022-08-14
    • 1970-01-01
    • 2018-09-24
    • 2018-08-11
    • 2019-09-16
    • 1970-01-01
    • 1970-01-01
    • 2011-07-29
    • 2018-08-27
    相关资源
    最近更新 更多