I need to upgrade my Postgres version. 9.6 to 14.x on deployment yaml file. But I need to keep my old Postgres data and bin folders for the new version of Postgres. When I update and apply the Postgres version in the deployment yaml file. My pod will be changed, and after this change, I want to use the same files(bin and data) for the new version. How can I do this just by updating the yaml file?
My Deployment file:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: postgres
spec:
  replicas: 1
  template:
    metadata:
      labels:
        name: postgres
    spec:
      containers:
      - name: postgres
        imagePullPolicy: Never
        image: postgres:9.6   # will be changed to 14.x version
        ports:
        - name: postgres
          containerPort: 5432
        volumeMounts:
        - mountPath: /var/lib/postgresql
          name: postgres-persistent-storage
      volumes:
      - name: postgres-persistent-storage
        persistentVolumeClaim:
          claimName: postgres-pv-claim
