gpt4 book ai didi

kubernetes - 我如何通过命令行进行此部署

转载 作者:行者123 更新时间:2023-12-02 12:23:30 26 4
gpt4 key购买 nike

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



我一直在想像这样

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,但不会在外部公开该服务。

最佳答案

您服务的选择器错误。应该从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"
}
}

关于kubernetes - 我如何通过命令行进行此部署,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37060905/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com