codependent
codependent

Reputation: 24452

Can't upgrade Deployment from apiVersion extensions/v1beta1 to apps/v1, it uses extensions/v1beta1 automatically

I currently have a GKE Kubernetes 1.15 cluster and I'm planning to upgrade to 1.16. Since 1.16 doesn't support certain APIs I have to change my deployments from extensions/v1beta1 to apps/v1.

Using this simple 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

When I apply it into my 1.15 cluster: kubectl -n mynamespace deployment.yml, what is actually see is the following (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: |
...

As you can see the actual apiVersion is extensions/v1beta1 instead of apps/v1. Why isn't it applying the version I specified?

UPDATE:

This is my kubectl version:

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"}

Upvotes: 4

Views: 5601

Answers (3)

Idiono-mfon Anthony
Idiono-mfon Anthony

Reputation: 21

Simply do this:

Install kubetcl convert via the link below:

https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/

The command below will convert your deployment.yaml (of apiversion: extensions/v1beta1 to apps/v1), and write it to a new file deploy.yaml

kubectl convert -f deployment.yaml --local -o yaml > deploy.yaml

Upvotes: 1

Mikuso
Mikuso

Reputation: 1350

The apiVersion returned from kubectl get won't necessarily match up with the actual apiVersion of your current configuration.

See here: https://github.com/kubernetes/kubernetes/issues/62283#issuecomment-380968868

Quote:

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.

Upvotes: 4

Malgorzata
Malgorzata

Reputation: 7023

Luckily kubectl, the CLI swiss knife has a tool to help with this conversion. If you have any old manifests that are throwing this error, add kubectl convert into the pipeline and it should work properly with Kubernetes 1.16.

Please take a look here: apiversions-update.

kubectl convert command has changed the API versions to be compatible for k8s 1.16. You just need to make sure that you use a recent version of kubectl to have the convert option built into it.

Upvotes: 1

Related Questions