0

I am new to Kubernetes and trying to run a data migration job before deploying my main service. To achieve this, I've written a new 'job.yaml' using "helm.sh/hook": pre-instal.

After deployment, from the logs of container it is clear that all migration code executed successfully.

Even though the migration container completes successfully, the pre-install Job itself fails to succeed and remains in an active status. Consequently, the deployment of the main service does not proceed.

I have thoroughly checked the logs and executed kubectl get events, but there are no error messages reported. I am confused about why the pre-install Job does not mark itself as successful, despite the successful completion of the migration container.

Could someone kindly help me identify the root cause of this issue and provide guidance on how to ensure that the pre-install Helm hook Job succeeds after the migration container has completed its task? Your assistance is greatly appreciated. Thank you!

new job.yaml

apiVersion: batch/v1
kind: Job
metadata:
  name: qdm-migration-service-job
  namespace: qdm
  annotations:
    "helm.sh/hook": pre-install,pre-upgrade
    "helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded

spec:
  backoffLimit: 1
  template:
    metadata:
      labels:
        app: qdm-migration-service-job-pod
        app.kubernetes.io/instance: {{ .Release.Name }}
    spec:
      serviceAccountName: qdm
      imagePullSecrets:
      - name: {{dockerhubsecret}}
      restartPolicy: Never
      containers:
      - name: qdm-migration-service
        terminationMessagePath: "/hook-completed"
        image: qdm-migration-service:1.0
        imagePullPolicy: Always
        securityContext:
          runAsUser: 0
        env:
        .............
        ports:
          - name: http
            containerPort: 8092
            protocol: TCP
    ```




Application main class:

public class QdmMigrationApp {
    public static void main(String[] args) {

        try {
            

            
           // all migrations logic
              ...........
              ...........

            System.out.println("QDM Migration Success!");
            writeTerminationMessage();
        }catch(Exception e){
            e.printStackTrace();
        }
    }


    private static void writeTerminationMessageToFile() {
        String terminationMessage = "Job completed !";
        String filePath = "/hook-completed";

        try (BufferedWriter writer = new BufferedWriter(new FileWriter(filePath))) {
            writer.write(terminationMessage);
        } catch (IOException e) {
            logger.error(e.getMessage());
            // Handle any exceptions that might occur during file writing
            e.printStackTrace();
        }
    }

Pod status:

kubectl describe qdm-migration-service-job-s9qvs -n qdm
Name:             qdm-migration-service-job-s9qvs
Namespace:        qdm
.......
Status:           Running
Controlled By:  Job/qdm-migration-service-job
Init Containers:
  copy-vault-env:
    .......
    State:          Terminated
      Reason:       Completed
      Exit Code:    0
      Started:      Thu, 20 Jul 2023 10:40:35 +0530
      Finished:     Thu, 20 Jul 2023 10:40:35 +0530
    Ready:          True
    Restart Count:  0
..........
Containers:
  vault-agent:
    Container ID:  cri-o://f703a9c050a5b391fbe1c.....
    Image:         docker.*******.com/qdm-images/qdm-vault:1.8.0
    Image ID:      ****
    Port:          <none>
    Host Port:     <none>
    State:          Running
      Started:      Thu, 20 Jul 2023 10:40:36 +0530
    Ready:          True
    Restart Count:  0
    Limits:
      cpu:     100m
      memory:  128Mi
    Requests:
      cpu:     100m
      memory:  128Mi
    Environment:
      VAULT_ADDR:         https://vault.******:8200
      VAULT_SKIP_VERIFY:  true
  qdm-migration-service:
    Container ID:  cri-o://f47d3aedc4ed6902da4459***
    Image:         ****
    Image ID:      ****
    Port:          8092/TCP
    Host Port:     0/TCP
    Command:
      /vault/vault-env
    State:          Terminated
      Reason:       Completed
      Message:      Job completed successfully!
      Exit Code:    0
      Started:      Thu, 20 Jul 2023 10:40:47 +0530
      Finished:     Thu, 20 Jul 2023 10:44:17 +0530
    Ready:          False
    Restart Count:  0
    Limits:
      cpu:     2
      memory:  5Gi
    Requests:
      cpu:     2
      memory:  4Gi
    Environment:
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-dbtsv (ro)
      /vault/ from vault-env (rw)
      /vault/secrets from agent-secrets (rw)
Conditions:
  Type              Status
  Initialized       True 
  Ready             False 
  ContainersReady   False 
  PodScheduled      True 
Volumes:
  .....
Tolerations:     node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                 node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type    Reason     Age   From               Message
  ----    ------     ----  ----               -------
  Normal  Scheduled  23m   default-scheduler  Successfully assigned qdm/qdm-migration-service-job-s9qvs to 10.1.7.123
  Normal  Pulled     23m   kubelet            Container image "*****" already present on machine
  Normal  Created    23m   kubelet            Created container copy-vault-env
  Normal  Started    23m   kubelet            Started container copy-vault-env
  Normal  Pulled     23m   kubelet            Container image "d*******" already present on machine
  Normal  Created    23m   kubelet            Created container vault-agent
  Normal  Started    23m   kubelet            Started container vault-agent
  Normal  Pulling    23m   kubelet            Pulling image "****qdm-pdb-migration-service:5.0"
  Normal  Pulled     23m   kubelet            Successfully pulled image "****qdm-pdb-migration-service:5.0" in 10.9s
  Normal  Created    23m   kubelet            Created container qdm-pdb-migration-service
  Normal  Started    23m   kubelet            Started container qdm-pdb-migration-service
David Maze
  • 130,717
  • 29
  • 175
  • 215
aks
  • 1
  • 1
  • The Vault Agent sidecar is keeping your Job from completing. [hashicorp/vault#11089](https://github.com/hashicorp/vault/issues/11089) describes the situation a little further. Does your Job need secrets from Vault? [Terminate istio sidecar istio-proxy for a kubernetes job / cronjob](https://stackoverflow.com/questions/54921054/terminate-istio-sidecar-istio-proxy-for-a-kubernetes-job-cronjob) is a similar question for a different technology with injected sidecars and you also might find inspiration there (but not a copy-paste answer). – David Maze Jul 20 '23 at 10:25

0 Answers0