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-convert
mv kubectl-convert /usr/local/bin/ -
Use the
--help
option to confirm the plugin is correctly configured:kubectl-convert --help
Verify the Conversion
-
Example manifest with a deprecated API version:
# ingress-old.yml
apiVersion: networking.k8s.io/v1beta1 # Deprecated version
kind: Ingress
metadata:
name: ingress-space
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /video-service
pathType: Prefix
backend:
serviceName: ingress-svc
servicePort: 80 -
Use
kubectl-convert
to update the deprecated API version:kubectl-convert -f ingress-old.yaml --output-version networking.k8s.io/v1
This will output the new file format.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
creationTimestamp: null
name: ingress-space
spec:
rules:
- http:
paths:
- backend:
service:
name: ingress-svc
port:
number: 80
path: /video-service
pathType: Prefix
status:
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