kubernetes 在版本“extensions/v1 beta1”中没有匹配类型“Deployment”

ttcibm8c  于 2023-08-03  发布在  Kubernetes
关注(0)|答案(8)|浏览(116)

在部署mojaloop时,Kubernetes会返回以下错误:
错误:验证失败:[无法识别“”:在版本“apps/v1 beta2”中没有与类型“Deployment”匹配的项,无法识别“”:在版本“extensions/v1 beta1”中没有与类型“Deployment”匹配的项,无法识别“”:在版本“apps/v1 beta2”中没有与类型“StatefulSet”匹配的项,无法识别“”:在版本“apps/v1 beta1”中没有与类型“StatefulSet”匹配的项]
Kubernetes版本是1.16。
如何解决API版本的问题?
通过调查,我发现Kubernetes不支持apps/v1 beta2,apps/v1 beta1。
如何让Kubernetes使用未弃用的版本或其他支持的版本?
我是Kubernetes的新手,任何可以支持我的人我都很高兴

xytpbqjk

xytpbqjk1#

在Kubernetes 1.16中,一些api被改变了。
您可以检查哪些API支持当前的Kubernetes对象

$ kubectl api-resources | grep deployment
deployments                       deploy       apps                           true         Deployment

字符串
这意味着只有带有apps的apiVersion才适用于Deployments(extensions不支持Deployment)。StatefulSet的情况相同。
您需要将Deployment和StatefulSet apiVersion更改为apiVersion: apps/v1
如果这没有帮助,请将您的YAML添加到问题中。

编辑由于HEM模板在Deployments中包含了旧apiVersions(版本1.16不支持)导致问题,有两种可能的解决方案:
1.git clone整个存储库并使用脚本将apiVersion替换为apps/v1中的所有模板/deployment.yaml
**2.**当验证器接受extensionsDeploymentStatefulSet时,使用旧版本的Kubernetes(1.15)。

new9mtju

new9mtju2#

要将较旧的Deployment转换为apps/v1,可以运行:

kubectl convert -f ./my-deployment.yaml --output-version apps/v1

字符串

xriantvc

xriantvc3#

您也可以手动更改。取舵图:

helm fetch --untar stable/metabase

字符串
访问图表文件夹:

cd ./metabase


更改API版本:

sed -i 's|extensions/v1beta1|apps/v1|g' ./templates/deployment.yaml


添加spec.selector.matchLabels

spec:
[...]
selector:
    matchLabels:
    app: {{ template "metabase.name" . }}
[...]


最后,安装您更改的图表:

helm install ./ \
  -n metabase \
  --namespace metabase \
  --set ingress.enabled=true \
  --set ingress.hosts={metabase.$(minikube ip).nip.io}


好好享受吧!

wmvff8tz

wmvff8tz4#

我更喜欢kubectl explain

# kubectl explain deploy
KIND:     Deployment
VERSION:  apps/v1

DESCRIPTION:
     Deployment enables declarative updates for Pods and ReplicaSets.

FIELDS:
   apiVersion   <string>
     APIVersion defines the versioned schema of this representation of an
     object. Servers should convert recognized schemas to the latest internal
     value, and may reject unrecognized values. More info:
     https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources

   kind <string>
     Kind is a string value representing the REST resource this object
     represents. Servers may infer this from the endpoint the client submits
     requests to. Cannot be updated. In CamelCase. More info:
     https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds

   metadata     <Object>
     Standard object metadata.

   spec <Object>
     Specification of the desired behavior of the Deployment.

   status       <Object>
     Most recently observed status of the Deployment.

字符串
使用kubectl explain,您还可以查看对象的特定参数:

# kubectl explain Service.spec.externalTrafficPolicy
KIND:     Service
VERSION:  v1

FIELD:    externalTrafficPolicy <string>

DESCRIPTION:
     externalTrafficPolicy denotes if this Service desires to route external
     traffic to node-local or cluster-wide endpoints. "Local" preserves the
     client source IP and avoids a second hop for LoadBalancer and Nodeport type
     services, but risks potentially imbalanced traffic spreading. "Cluster"
     obscures the client source IP and may cause a second hop to another node,
     but should have good overall load-spreading.

aij0ehis

aij0ehis5#

简单地说,您不会强制当前安装使用过时版本的API;你在你的配置文件中修正版本。如果你想查看你当前的kube支持哪个版本,可以运行:

root@ubn64:~# kubectl api-versions | grep -i apps

apps/v1

字符串

xe55xuns

xe55xuns6#

我在出错以下-
错误:无法识别“deploye.yaml”:在版本“extensions/v1 beta1”中没有匹配类型“Deployment”
对我有效的解决方案-

修改了apiVersion中的行:extensions/v1beta1 to apiVersion:部署中的apps/v1。yaml

原因-我们升级了K8群集,因此发生了此错误。

omqzjyyz

omqzjyyz7#

这让我很恼火,因为我正在测试大量的helm包,所以我写了一个快速脚本--它可以被修改来排序你的工作流程,也许见下面
新工作流首先将图表作为tgz提取到您的工作目录中

helm fetch repo/chart

字符串
然后在您的工作中直接运行下面的bash脚本-我命名为helmk

helmk myreleasename mynamespace chart.tgz [any parameters for kubectl create]


helmk的内容-需要编辑您的kubeconfig集群名称才能工作

#!/bin/bash
echo usage $0 releasename namespace chart.tgz [createparameter1] [createparameter2] ... [createparameter n]
echo This will use your namespace then shift back to default so be careful!!
kubectl create namespace $2   #this will create harmless error if namespace exists have to ignore
kubectl config set-context MYCLUSTERNAME --namespace $2
helm template -n $1 --namespace $2 $3 | kubectl convert -f /dev/stdin | kubectl create --save-config=true ${@:4}  -f /dev/stdin
#note the --namespace parameter in helm template above seems to be ignored so we have to manually switch context
kubectl config set-context MYCLUSTERNAME --namespace default


这是一个有点危险的黑客,因为我手动切换到你想要的新名称空间上下文,然后再回来,所以只用于单用户开发者,真的或注解出来。
您将收到一个关于使用Kubectl Convert工具的警告,如下所示
如果你需要编辑YAML来自定义-只需要将/dev/stdin中的一个替换为中间文件,但最好是使用“create”和save-config,然后简单地“apply”你的更改,这意味着它们也会被记录在kubernetes中。祝你好运

a9wyjsp7

a9wyjsp78#

我在一个集群上遇到了同样的问题,该集群升级到了不支持某些API版本(v1.17和apps/v1 beta2)。

$ helm get manifest some-deployment
...
# Source: some-deployment/templates/deployment.yaml
apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: some-deployment
  labels:
...

字符串
查看Helm文档,清单文件似乎存储在集群中供Helm引用,它可能包含无效的API版本,从而导致错误。
建议的两种方法是手动编辑清单(一个相当繁琐的多阶段过程),或者使用一个名为mapkubeapis的helm插件自动编辑清单。

$ helm plugin install https://github.com/helm/helm-mapkubeapis


它可以运行--dry-run标志来模拟效果:

$ helm mapkubeapis --dry-run some-deployment
2021/02/15 09:33:29 NOTE: This is in dry-run mode, the following actions will not be executed.
2021/02/15 09:33:29 Run without --dry-run to take the actions described below:
2021/02/15 09:33:29
2021/02/15 09:33:29 Release 'some-deployment' will be checked for deprecated or removed Kubernetes APIs and will be updated if necessary to supported API versions.
2021/02/15 09:33:29 Get release 'some-deployment' latest version.
2021/02/15 09:33:30 Check release 'some-deployment' for deprecated or removed APIs...
2021/02/15 09:33:30 Found deprecated or removed Kubernetes API:
"apiVersion: apps/v1beta2
kind: Deployment"
Supported API equivalent:
"apiVersion: apps/v1
kind: Deployment"
2021/02/15 09:33:30 Finished checking release 'some-deployment' for deprecated or removed APIs.
2021/02/15 09:33:30 Deprecated or removed APIs exist, updating release: some-deployment.
2021/02/15 09:33:30 Map of release 'some-deployment' deprecated or removed APIs to supported versions, completed successfully.


然后在没有标志的情况下运行以应用改变。

相关问题