4
votes

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"}
2
How old is your kubectl? That's what determines which version it asks for.coderanger
I have an up-to-date version: brew upgrade kubernetes-cli -> kubernetes-cli 1.17.4 already installedcodependent
Check with kubectl version. Sometimes people end up with an old version from google stuff.coderanger

2 Answers

4
votes

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.

1
votes

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.