Changing deprecated API versions
Updated Apr 07, 2022 ·
Overview
This scenario was encountered during CKA and CKAD exam study.
As Kubernetes evolves, some API versions become deprecated. It's important to update these to newer, supported versions to avoid issues in future updates.
Install the kubectl convert
To install the kubectl convert plugin on the control plane node, follow these steps:
-
Download the latest version:
curl -LO https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl-convert -
Change the file permissions and move it to
/usr/local/bin/:chmod +x kubectl-convertmv kubectl-convert /usr/local/bin/ -
Use the
--helpoption to confirm the plugin is correctly configured:kubectl-convert --help
Verify the Conversion
-
Example manifest with a deprecated API version:
# ingress-old.ymlapiVersion: networking.k8s.io/v1beta1 # Deprecated versionkind: Ingressmetadata:name: ingress-spaceannotations:nginx.ingress.kubernetes.io/rewrite-target: /spec:rules:- http:paths:- path: /video-servicepathType: Prefixbackend:serviceName: ingress-svcservicePort: 80 -
Use
kubectl-convertto update the deprecated API version:kubectl-convert -f ingress-old.yaml --output-version networking.k8s.io/v1This will output the new file format.
apiVersion: networking.k8s.io/v1kind: Ingressmetadata:annotations:nginx.ingress.kubernetes.io/rewrite-target: /creationTimestamp: nullname: ingress-spacespec:rules:- http:paths:- backend:service:name: ingress-svcport:number: 80path: /video-servicepathType: Prefixstatus:loadBalancer: {} -
Save the converted version to a new file:
kubectl-convert -f ingress-old.yaml --output-version networking.k8s.io/v1 > ingress-new.yaml -
Apply the new manifest:
kubectl apply -f ingress-new.yaml -
Verify the changes. Check the ingress resource:
kubectl get ing ingress-space -o yaml | grep -i apiversion