当我分两步构建Kubernetes服务时(1.复制控制器; 2.暴露复制控制器),我的公开服务获取外部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
但是,如果我一步完成,Service
和ReplicationController
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
外部知识产权下的<none>
让我担心。
对于服务,我使用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"
答案 0 :(得分:3)
如果未指定服务类型,则默认为ClusterIP。如果你想要等同于expose
,你必须:
type=LoadBalancer