尝试执行helm install
错误:无法从发布清单构建kubernetes对象: [无法识别“”:版本中与“服务”类型不匹配 “ extensions / v1beta1”,验证错误“”:验证数据错误: ValidationError(Deployment.spec):在中缺少必填字段“选择器” io.k8s.api.apps.v1.DeploymentSpec]
我的service.yaml
如下所示
apiVersion: extensions/v1beta1
kind: Service
metadata:
name: helm-xxx-helper-api
spec:
type: NodePort
ports:
- nodePort: 31235
port: 80
targetPort: 8080
selector:
app: helm-xxx-helper
我的deployment.yaml
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: helm-xxx-helper
spec:
replicas: 2
selector:
matchLabels:
name: helm-xxx-helper
template:
metadata:
labels:
app: helm-xxx-helper
spec:
containers:
- name: helm-xxx-helper
image: xxxxxxxxx:5001/devops/xxx-helper:latest
imagePullPolicy: Always
env:
- name: XXX_STAGE
value: "DEV"
ports:
- containerPort: 8080
这里可能是什么问题?
答案 0 :(得分:1)
在选择器中尝试
selector:
matchLabels:
app: helm-xxx-helper
答案 1 :(得分:1)
收到此错误表示您正在使用Kubernetes 1.16或更高版本。
问题1 -使用Service
在此版本中,许多apiVersion
已更改(部署,StatefulSet,服务)。可以在here中找到更多详细信息。
在Kubernetes 1.16中,您需要对apiVersion: v1
使用service
。否则,您会收到类似
error: unable to recognize "STDIN": no matches for kind "Service" in version "extensions/v1beta1"
error: unable to recognize "STDIN": no matches for kind "Service" in version "extensions/v1"
error: unable to recognize "STDIN": no matches for kind "Service" in version "apps/v1"
问题2 -使用Deployment
。
spec.selector.matchLabels
不包含name
之类的值。您需要使用labels
中的值。因此,在这种情况下,您需要使用name: helm-xxx-helper
而不是app: helm-xxx-helper
,否则会收到类似以下的错误消息:The Deployment "helm-xxx-helper" is invalid: spec.template.metadata.labels: Invalid value: map[string]string{"app":"helm-xxx-helper"}: `selector` does not match template `labels`
...
selector:
matchLabels:
name: helm-xxx-helper
...
matchLabels
的值应小于3个字母(t)。另外,正如我在前面提到的那样,您需要将name
更改为app
正确格式为matchLables
的正确格式:
...
selector:
matchLabels:
app: helm-xxx-helper
...
您可以阅读有关Labels
和Selectors
here的信息。
正如您提到的HELM
,您需要将Kubernetes version
更改为早于1.16,或者在apiVersion
目录中的每个对象YAML中更改template
。
已经有一个类似的案例。请检查this thread了解更多信息。
将同时创建两个Service
和Deployment
的YAML。在Kubernetes 1.16.1上进行了测试。
apiVersion: v1
kind: Service
metadata:
name: helm-xxx-helper-api
spec:
type: NodePort
ports:
- nodePort: 31235
port: 80
targetPort: 8080
selector:
app: helm-xxx-helper
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: helm-xxx-helper
spec:
replicas: 2
selector:
matchLabels:
app: helm-xxx-helper
template:
metadata:
labels:
app: helm-xxx-helper
spec:
containers:
- name: helm-xxx-helper
image: nginx # As I dont have your image ive put nginx
imagePullPolicy: Always
env:
- name: XXX_STAGE
value: "DEV"
ports:
- containerPort: 8080