kubectl convert — Update api versions automatically

Raja Venkataraman
Star Systems Labs
Published in
3 min readSep 29, 2019

Kubernetes is fast moving, they throw a release every quarter, so it’s quite hard to keep up with it as well as make sure that the api versions are updated automatically.

For those that started using Kubernetes recently but jumped into the 1.16 release (because its the latest and greatest), or for those of us who upgraded to Kubernetes 1.16, there must be a point when it threw out errors like

no matches for kind ”DaemonSet” in version ”extensions/v1beta1”

or

no matches for kind ”Deployment” in version ”extensions/v1beta1”

and we wouldn’t know what to do, because the guide that we have been following says to do that and it worked for them!!!!

The reason being that Kubernetes has deprecated a few kinds from extensions/v1beta1 API group. This is what they said (API Deprecations in 1.16)

NetworkPolicy (in the extensions/v1beta1 API group)

Migrate to use the networking.k8s.io/v1 API, available since v1.8. Existing persisted data can be retrieved/updated via the networking.k8s.io/v1 API.

PodSecurityPolicy (in the extensions/v1beta1 API group)

Migrate to use the policy/v1beta1 API, available since v1.10. Existing persisted data can be retrieved/updated via the policy/v1beta1 API.

DaemonSet, Deployment, StatefulSet, and ReplicaSet (in the extensions/v1beta1 and apps/v1beta2 API groups)

Migrate to use the apps/v1 API, available since v1.9. Existing persisted data can be retrieved/updated via the apps/v1 API.

So, what do we do now? Luckily kubectl, the CLI swiss knife has a tool to help us 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.

for e.g. if i had a deployment with something like

emerald:tmp raja$ grep -C 3 'extensions/v1beta1' calico.yaml
# as the Calico CNI plugins and network config on
# each master and worker node in a Kubernetes cluster.
kind: DaemonSet
apiVersion: extensions/v1beta1
metadata:
name: calico-node
namespace: kube-system
--
--
---
# This manifest deploys the Calico Kubernetes controllers.
# See https://github.com/projectcalico/kube-controllers
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: calico-kube-controllers

Note the API Versions highlighted above.

Running through kubectl convert , this now becomes

emerald:tmp raja$ kubectl convert -f calico.yaml | grep -C 3 'apps/v'
creationTimestamp: null
name: calico-etcd-secrets
type: Opaque
- apiVersion: apps/v1
kind: DaemonSet
metadata:
annotations:
--
--
metadata:
creationTimestamp: null
name: calico-node
- apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null

As you can see above, kubectl convert 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.

If you had a file that you used from the internet where they said something like

kubectl apply -f <URL>

which threw the above error, then you could convert it into a

kubectl convert -f <URL> | kubectl create -f -

to get it working with Kubernetes 1.16.

Happy k8s-ing !!!

Note: kubectl convert maybe removed in kubernetes 1.17 or converted into another format as discussed in https://github.com/kubernetes/kubectl/issues/725. Till such a decision is made, this will definitely be helpful for people trying 1.16

--

--