kubernetes - ValidationError:io.k8s.api.v1.DeploymentSpec 中缺少必填字段“选择器”
问题描述
我已经创建了 Hyper-V 机器并尝试使用 Sawtooth YAML 文件在 Minikube 上部署 Sawtooth: https ://sawtooth.hyperledger.org/docs/core/nightly/master/app_developers_guide/sawtooth-kubernetes-default.yaml
我将 apiVersion ie 更改apiVersion: extensions/v1beta1
为 apiVersion: apps/v1
,尽管我使用此命令在 Kubernetes v1.17.0 中启动了 Minikube
minikube 启动 --kubernetes-version v1.17.0
之后我无法部署服务器。命令是
kubectl apply -f 锯齿-kubernetes-default.yaml --validate=false
它显示错误“sawtooth-0”无效。
---
apiVersion: v1
kind: List
items:
- apiVersion: apps/v1
kind: Deployment
metadata:
name: sawtooth-0
spec:
replicas: 1
selector:
matchLabels:
name: sawtooth-0
template:
metadata:
labels:
name: sawtooth-0
spec:
containers:
- name: sawtooth-devmode-engine
image: hyperledger/sawtooth-devmode-engine-rust:chime
command:
- bash
args:
- -c
- "devmode-engine-rust -C tcp://$HOSTNAME:5050"
- name: sawtooth-settings-tp
image: hyperledger/sawtooth-settings-tp:chime
command:
- bash
args:
- -c
- "settings-tp -vv -C tcp://$HOSTNAME:4004"
- name: sawtooth-intkey-tp-python
image: hyperledger/sawtooth-intkey-tp-python:chime
command:
- bash
args:
- -c
- "intkey-tp-python -vv -C tcp://$HOSTNAME:4004"
- name: sawtooth-xo-tp-python
image: hyperledger/sawtooth-xo-tp-python:chime
command:
- bash
args:
- -c
- "xo-tp-python -vv -C tcp://$HOSTNAME:4004"
- name: sawtooth-validator
image: hyperledger/sawtooth-validator:chime
ports:
- name: tp
containerPort: 4004
- name: consensus
containerPort: 5050
- name: validators
containerPort: 8800
command:
- bash
args:
- -c
- "sawadm keygen \
&& sawtooth keygen my_key \
&& sawset genesis -k /root/.sawtooth/keys/my_key.priv \
&& sawset proposal create \
-k /root/.sawtooth/keys/my_key.priv \
sawtooth.consensus.algorithm.name=Devmode \
sawtooth.consensus.algorithm.version=0.1 \
-o config.batch \
&& sawadm genesis config-genesis.batch config.batch \
&& sawtooth-validator -vv \
--endpoint tcp://$SAWTOOTH_0_SERVICE_HOST:8800 \
--bind component:tcp://eth0:4004 \
--bind consensus:tcp://eth0:5050 \
--bind network:tcp://eth0:8800"
- name: sawtooth-rest-api
image: hyperledger/sawtooth-rest-api:chime
ports:
- name: api
containerPort: 8008
command:
- bash
args:
- -c
- "sawtooth-rest-api -C tcp://$HOSTNAME:4004"
- name: sawtooth-shell
image: hyperledger/sawtooth-shell:chime
command:
- bash
args:
- -c
- "sawtooth keygen && tail -f /dev/null"
- apiVersion: apps/v1
kind: Service
metadata:
name: sawtooth-0
spec:
type: ClusterIP
selector:
name: sawtooth-0
ports:
- name: "4004"
protocol: TCP
port: 4004
targetPort: 4004
- name: "5050"
protocol: TCP
port: 5050
targetPort: 5050
- name: "8008"
protocol: TCP
port: 8008
targetPort: 8008
- name: "8800"
protocol: TCP
port: 8800
targetPort: 8800
解决方案
您需要修复您的部署yaml
文件。正如您从错误消息中看到的那样,该Deployment.spec.selector
字段不能为空。
更新yaml
(即添加spec.selector
)如下所示:
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: sawtooth-0
template:
metadata:
labels:
app.kubernetes.io/name: sawtooth-0
- 为什么
selector
领域很重要?
该selector
字段定义了 Deployment 如何找到要管理的 Pod。app.kubernetes.io/name: sawtooth-0
在这种情况下,您只需选择在 Pod 模板 ( )中定义的标签。然而,更复杂的选择规则是可能的,只要 Pod 模板本身满足规则。
更新:
apiVersion
k8s的服务是v1
:
- apiVersion: v1 # Update here
kind: Service
metadata:
app.kubernetes.io/name: sawtooth-0
spec:
type: ClusterIP
selector:
app.kubernetes.io/name: sawtooth-0
... ... ...
推荐阅读
- matrix - 优化 C 中的矩阵计算
- c# - 找不到 GET 的路由 / - 无法提供默认 index.html
- ios - 将 iPhone X 状态栏样式颜色更改为白色
- intellij-idea - 如何在“长单字符串”异常下强制在 Intellij 中启用软包装?
- swift - 无法将“_SwiftValue”(0x1106695f8)类型的值转换为“NSArray”(0x110112598)
- python-3.x - 使用 celerybeat-mongo 将 celery 任务发送到定义的队列
- wordpress - 如何从过滤后的 perpage 和特定页面 wordpress API 链接中获取 rest json 返回
- ubuntu - Lynx 浏览器在哪里下载文件?
- c# - 尝试将数据插入数据库时,Dapper 给出未处理的异常
- ios - 我们如何在uitableview swift中使用不可见的单元格?