Intro
Kubernetes deprecates API versions over time. Usually this affects alpha and beta versions and only requires changing the apiVersion: line in your resource file to make it work.However with this Ingress object version change, additional changes are necessary.
Basics
For this post I am quickly creating a new cluster via Kind (Kubernetes in Docker). Once done, we can see which API versions are supported by this cluster (version v1.21.1).
$ kubectl api-versions | grep networking
networking.k8s.io/v1
networking.k8s.io/v1beta1
Kubernetes automatically converts existing resources internally into different supported API versions. So if we create a new Ingress object with version v1beta1 on a recent cluster version, you will receive a deprecation warning - and the same Ingress object will exist both in version v1beta1 and v1.
Create
$ cat ingress_beta.yaml
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: clusterpirate-ingress
spec:
rules:
- http:
paths:
- path: /clusterpirate
backend:
serviceName: clusterpirate
servicePort: 8090
$ kubectl apply -n default -f ingress_beta.yaml
Warning: networking.k8s.io/v1beta1 Ingress is deprecated in v1.19+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress
ingress.networking.k8s.io/clusterpirate-ingress created
Check
To verify this, you can view or export the same resource in the required API version and get a different document back. This also helps with the actual migration, as it includes the required layout or configuration.
$ kubectl get ingress.v1beta1.networking.k8s.io -n default clusterpirate-ingress -o yaml
Warning: networking.k8s.io/v1beta1 Ingress is deprecated in v1.19+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
spec:
rules:
- http:
paths:
- backend:
serviceName: clusterpirate
servicePort: 8090
path: /clusterpirate
$ kubectl get ingress.v1.networking.k8s.io -n default clusterpirate-ingress -o yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
spec:
rules:
- http:
paths:
- backend:
service:
name: clusterpirate
port:
number: 8090
path: /clusterpirate
pathType: ImplementationSpecific
Migrate
To change your Ingress objects (within helm charts for example), we need to change the apiVersion: as well as adding the pathType: field, which can be either Prefix or ImplementationSpecific.
$ diff ingress_beta.yaml ingress_v1.yaml
1c1
< apiVersion: networking.k8s.io/v1beta1
---
> apiVersion: networking.k8s.io/v1
9a10
> pathType: Prefix
11,12c12,15
< serviceName: clusterpirate
< servicePort: 8090
---
> service:
> name: clusterpirate
> port:
> number: 8090
Conclusions
- API versions change over time.
- Kubernetes tracks resources internally in different versions.
- Usually the version upgrade process is somewhat easier.
Comments
Post a Comment