无法将Deployment从apiVersion扩展/ v1beta1升级到apps / v1,它会自动使用扩展/ v1beta1

时间:2020-03-19 09:51:09

标签: kubernetes google-kubernetes-engine kubectl kubernetes-deployment

我目前有一个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"}

2 个答案:

答案 0 :(得分:2)

kubectl get返回的apiVersion不一定与您当前配置的实际apiVersion匹配。

查看此处:https://github.com/kubernetes/kubernetes/issues/62283#issuecomment-380968868

报价:

kubectl get使用服务器优先顺序,它将优先使用extensions API组以实现向后兼容性,直到删除extensions为止。也就是说,kubectl get deployment默认使用extensions / v1beta1端点。

要在apps API组下进行部署,可以使用kubectl get deployment.apps,它返回apps/v1部署。

答案 1 :(得分:1)

幸运的是,CLI瑞士刀kubectl有一个工具可以帮助完成这种转换。如果您有任何引发此错误的旧清单,请将navigation.state.params添加到管道中,它应与Kubernetes 1.16一起正常工作。

请在这里查看:apiversions-update

import {TabBarBottom, TabNavigator} from 'react-navigation'; import {MyIcon, AnotherIcon} from './icons.js'; export default TabNavigator({ Home: {screen: HomeRouter}, Profile: {screen: ProfileRouter}, }, { navigationOptions: ({navigation}) => ({ tabBarIcon: ({focused}) => { const {routeName, params} = navigation.state; ... if (params.data === 1) { return <AnotherIcon /> } ... return <MyIcon />; }, }), tabBarComponent: TabBarBottom, tabBarPosition: 'bottom', }); 命令已将API版本更改为与k8s 1.16兼容。您只需要确保使用最新版本的kubectl即可内置kubectl convert选项。