gpt4 book ai didi

kubernetes - 无效值 : "The edited file failed validation": ValidationError(Service. 规范): unknown field "nodePort" in io. k8s.api.core.v1.ServiceSpec

转载 作者:行者123 更新时间:2023-12-02 11:39:25 24 4
gpt4 key购买 nike

为了远程访问 Kubernetes 仪表板,我尝试按照建议将 ClusterIP 替换为 nodePort herehere .但是,编辑总是失败并出现以下错误:

Invalid value: "The edited file failed validation": ValidationError(Service.spec): unknown field "nodePort" in io.k8s.api.core.v1.ServiceSpec

以上引用推荐的命令是:

kubectl edit svc/kubernetes-dashboard --namespace=kube-system

这是 yaml 我在更改后尝试的内容:

apiVersion: v1
kind: Service
metadata
creationTimestamp: "2019-07-24T13:03:48Z"
labels:
k8s-app: kubernetes-dashboard
name: kubernetes-dashboard
namespace: kube-system
resourceVersion: "2238"
selfLink: /api/v1/namespaces/kube-system/services/kubernetes-dashboard
uid: 79c37d2b-ae13-11e9-b2a1-0026b95c3009
spec:
NodePort: 10.110.154.246
ports:
- port: 80
protocol: TCP
targetPort: 9090
selector:
k8s-app: kubernetes-dashboard
sessionAffinity: None
type: ClusterIP
status:
loadBalancer: {}

客户端和服务器版本的输出如下:

   $kubectl version
Client Version: version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.2", GitCommit:"cff46ab41ff0bb44d8584413b598ad8360ec1def", GitTreeState:"clean", BuildDate:"2019-01-10T23:35:51Z", GoVersion:"go1.11.4", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.8", GitCommit:"0c6d31a99f81476dfc9871ba3cf3f597bec29b58", GitTreeState:"clean", BuildDate:"2019-07-08T08:38:54Z", GoVersion:"go1.11.5", Compiler:"gc", Platform:"linux/amd64"}

最佳答案

您使用了错误的配置。 Kubernetes 服务的 spec 中没有名为 NodePort 的字段。您共享的文档告诉您将字段 spec.type 的值从 ClusterIP 更改为 NodePort。另一方面,您正在添加一个完全无效的新字段 spec.NodePort。看,https://kubernetes.io/docs/concepts/services-networking/service/#nodeport

像这样尝试,同时执行 kubectl edit:

apiVersion: v1
kind: Service
metadata
...
labels:
k8s-app: kubernetes-dashboard
name: kubernetes-dashboard
namespace: kube-system
...
spec:
ports:
- port: 80
protocol: TCP
targetPort: 9090
...
type: NodePort
...

或者只是运行这个:

kubectl get svc -n kube-system kubernetes-dashboard -o yaml | sed 's/type: ClusterIP/type: NodePort/' | kubectl replace -f - 

关于kubernetes - 无效值 : "The edited file failed validation": ValidationError(Service. 规范): unknown field "nodePort" in io. k8s.api.core.v1.ServiceSpec,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57184821/

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