Python application with input text file to be deployed on kubernetes from bitbucket and unzip the package

Viewed 68

Im a java developer but working on python for the first time

I have a python app which takes inputs from a text file input.txt.

both the program and input file will be in bitbucket.

How do we get this bitbucket repo to the kubernetes POD and access the python package from bitbucket directly and unzip it in the pod and run the application.

Please help.

1 Answers

There are multiple options you can use listing all here

  1. Add a file while creating the Docker image

    Add clone step in docker build or copy-paste if possible

RUN git clone git@bitbucket.org:User/repo.git

  1. Write the sidecar init container which will mount your both files to file system before the main container starts

You can perform all changes before the main container should star, so init first downloads the data after that can unzip it or copy-paste it as per the requirement to the filesystem and that same file system will be further used by the main container and it starts running as per config.

Ref :

    apiVersion: v1
    kind: Pod
    metadata:
      labels:
        run: nginx
      name: nginx
    spec:
      containers:
      - image: nginx
        name: nginx
        ports:
        - containerPort: 80
        volumeMounts:
        - mountPath: "/usr/share/nginx/html"
          name: www-data
      initContainers:
      - name: git-cloner
        image: alpine/git #Change image as per need and do all process here unzip,copy or anything you can set to file system and after this main container should start
        args:
            - clone
            - --single-branch
            - --
            - https://github.com/example 
            - /data
        volumeMounts:
        - mountPath: /data
          name: www-data
      volumes:
      - name: www-data
        emptyDir: {}
  1. You can also write you custom code and download files and set those into file system of POD however init container would be easy and good solution.
Related