无法将 Deployment 从 apiVersion extensions/v1beta1 升级到 apps/v1,它会自动使用 extensions/v1beta1
Can't upgrade Deployment from apiVersion extensions/v1beta1 to apps/v1, it uses extensions/v1beta1 automatically
我目前有一个 GKE Kubernetes 1.15 集群,我打算升级到 1.16。由于 1.16 不支持某些 API,我必须将我的部署从 extensions/v1beta1 更改为 apps/v1。
使用这个简单的 deployment.yml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
当我将它应用到我的 1.15 集群中时:kubectl -n mynamespace deployment.yml
,实际看到的是以下内容 (kubectl -n mynamespace get deployments nginx-deployment
):
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
deployment.kubernetes.io/revision: "1"
kubectl.kubernetes.io/last-applied-configuration: |
...
如您所见,实际的 apiVersion 是 extensions/v1beta1 而不是 apps/v1。为什么它不应用我指定的版本?
更新:
这是我的 kubectl 版本:
Client Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.4", GitCommit:"8d8aa39598534325ad77120c120a22b3a990b5ea", GitTreeState:"clean", BuildDate:"2020-03-12T23:41:24Z", GoVersion:"go1.14", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"15+", GitVersion:"v1.15.9-gke.24", GitCommit:"39e41a8d6b7221b901a95d3af358dea6994b4a40", GitTreeState:"clean", BuildDate:"2020-02-29T01:24:35Z", GoVersion:"go1.12.12b4", Compiler:"gc", Platform:"linux/amd64"}
幸运的是 kubectl,CLI 瑞士刀有一个工具可以帮助进行这种转换。如果您有任何抛出此错误的旧清单,请将 kubectl convert
添加到管道中,它应该可以与 Kubernetes 1.16 一起正常工作。
请看这里:apiversions-update。
kubectl convert
命令已将 API 版本更改为与 k8s 1.16 兼容。您只需要确保您使用的是最新版本的 kubectl,以便在其中内置 convert
选项。
从 kubectl get
返回的 apiVersion 不一定与您当前配置的实际 apiVersion 匹配。
看这里:https://github.com/kubernetes/kubernetes/issues/62283#issuecomment-380968868
引用:
kubectl get
uses server-preferred order, which will prefer the extensions
API group for backward compatibility, until extensions
is removed. That is to say, kubectl get deployment
uses extenions/v1beta1 endpoint by default.
To get deployments under apps
API group, you can use kubectl get deployment.apps
, which returns you apps/v1
deployments.
我目前有一个 GKE Kubernetes 1.15 集群,我打算升级到 1.16。由于 1.16 不支持某些 API,我必须将我的部署从 extensions/v1beta1 更改为 apps/v1。
使用这个简单的 deployment.yml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
当我将它应用到我的 1.15 集群中时:kubectl -n mynamespace deployment.yml
,实际看到的是以下内容 (kubectl -n mynamespace get deployments nginx-deployment
):
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
deployment.kubernetes.io/revision: "1"
kubectl.kubernetes.io/last-applied-configuration: |
...
如您所见,实际的 apiVersion 是 extensions/v1beta1 而不是 apps/v1。为什么它不应用我指定的版本?
更新:
这是我的 kubectl 版本:
Client Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.4", GitCommit:"8d8aa39598534325ad77120c120a22b3a990b5ea", GitTreeState:"clean", BuildDate:"2020-03-12T23:41:24Z", GoVersion:"go1.14", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"15+", GitVersion:"v1.15.9-gke.24", GitCommit:"39e41a8d6b7221b901a95d3af358dea6994b4a40", GitTreeState:"clean", BuildDate:"2020-02-29T01:24:35Z", GoVersion:"go1.12.12b4", Compiler:"gc", Platform:"linux/amd64"}
幸运的是 kubectl,CLI 瑞士刀有一个工具可以帮助进行这种转换。如果您有任何抛出此错误的旧清单,请将 kubectl convert
添加到管道中,它应该可以与 Kubernetes 1.16 一起正常工作。
请看这里:apiversions-update。
kubectl convert
命令已将 API 版本更改为与 k8s 1.16 兼容。您只需要确保您使用的是最新版本的 kubectl,以便在其中内置 convert
选项。
从 kubectl get
返回的 apiVersion 不一定与您当前配置的实际 apiVersion 匹配。
看这里:https://github.com/kubernetes/kubernetes/issues/62283#issuecomment-380968868
引用:
kubectl get
uses server-preferred order, which will prefer theextensions
API group for backward compatibility, untilextensions
is removed. That is to say,kubectl get deployment
uses extenions/v1beta1 endpoint by default.To get deployments under
apps
API group, you can usekubectl get deployment.apps
, which returns youapps/v1
deployments.