DEV Community

Carlos Nogueira
Carlos Nogueira

Posted on

How to Deploy YAMLs with Deprecated Parameters on Kubernetes 1.16.0

The Kubernetes version 1.16.0 stopped to serve the following deprecated APIs:

  1. 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.

  2. 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.

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

You must check your older YAMLs. But changing the listed parameters in all files can be an exhausting task.

An option would be to convert the older files.

For example, lets deploy a NGINX using the file nginx.yaml.

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  labels:
   run: nginx
  name: deploy-nginx
spec:
  selector:
     matchLabels:
      run: nginx
  template:
     metadata:
      labels:
        run: nginx
    spec:
      containers:
      - image: nginx
        name: nginx
Enter fullscreen mode Exit fullscreen mode

The files nginx.yaml sets apiVersion: extensions/v1beta1 and it's compatible with kubernetes older versions, but not run on The last.
To convert the older YAML, using client 1.16 execute kubectl with the option convert:

kubectl convert -f nginx.yaml
Enter fullscreen mode Exit fullscreen mode

Command screen output would be like:

apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    run: nginx
  name: deploy-nginx
spec:
  progressDeadlineSeconds: 2213489811
  revisionHistoryLimit: 2213489811
  selector:
    matchLabels:
      run: nginx
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
    type: RollingUpdate
  template:
    metadata:
      creationTimestamp: null
      labels:
        run: nginx
    spec:
      containers:
      - image: nginx
        imagePullPolicy: Always
        name: nginx
        resources: {}
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      restartiPolicy: Always
      schedulerName: defaul-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 28
status: {}
Enter fullscreen mode Exit fullscreen mode

Paste the command output to a file(ex: nginxOUT.yaml)

kubectl convert -f nginx.yaml > nginxOUT.yaml
Enter fullscreen mode Exit fullscreen mode

Deploy

Using output file

kubectl create -f nginxOUT.yaml
Enter fullscreen mode Exit fullscreen mode

Directly with the older file

kubectl convert -f nginx.yaml | kubectl create -f -
Enter fullscreen mode Exit fullscreen mode

References

https://kubernetes.io/blog/2019/07/18/api-deprecations-in-1-16/

Top comments (0)