How to upload a file to a running pod in GKE?

Overview :


In this article, we will walk through a step-by-step procedure to upload a file to a running pod in GKE. We will utilize Cloud Storage Buckets to store the file, and subsequently, retrieve it from the bucket and place it into the directory of the pod. We can do this directly by picking the file from your local if you have installed Google Cloud SDK, we will explore this solution later.

Install webmethods-microservicesruntime in GKE :


  • Navigate to your GCP console search for ‘Kubernetes Engine API‘ and enable it.
  • Navigate to the Kubernetes Engine page and create a cluster. You can adjust the settings as per your needs, or you can create the cluster with default settings.
  • Creating the cluster will take a few minutes. Once the cluster is created, click on the menu button of the cluster. You will see a “Connect” option. Clicking on “Connect” will provide you with the command to obtain credentials for kubectl, which is the Kubernetes command-line tool.
  • Run the command in the cloud shell.
  • Run the below query to deploy the webmethods-microservicesruntime image from the docker hub in GKE.
    Plain text
    Copy to clipboard
    Open code in new window
    EnlighterJS 3 Syntax Highlighter
    kubectl create deployment <Deployment - Name> --image=softwareag/webmethods-microservicesruntime:10.15
    Example :
    kubectl create deployment demois --image=softwareag/webmethods-microservicesruntime:10.15
    kubectl create deployment <Deployment - Name> --image=softwareag/webmethods-microservicesruntime:10.15 Example : kubectl create deployment demois --image=softwareag/webmethods-microservicesruntime:10.15
    kubectl create deployment <Deployment - Name> --image=softwareag/webmethods-microservicesruntime:10.15
    
    Example :
    kubectl create deployment demois --image=softwareag/webmethods-microservicesruntime:10.15
  • We have deployed our microservice on GKE. Now, run the following command to expose the deployment and make it accessible from outside.
    Plain text
    Copy to clipboard
    Open code in new window
    EnlighterJS 3 Syntax Highlighter
    kubectl expose deployment <DEPLOYMENT NAME> --type=LoadBalancer --port= <POSRT that needs to be used>
    Example :
    kubectl expose deployment demois --type=LoadBalancer --port=5555
    kubectl expose deployment <DEPLOYMENT NAME> --type=LoadBalancer --port= <POSRT that needs to be used> Example : kubectl expose deployment demois --type=LoadBalancer --port=5555
    kubectl expose deployment <DEPLOYMENT NAME> --type=LoadBalancer --port= <POSRT that needs to be used>
    
    Example :
    kubectl expose deployment demois --type=LoadBalancer --port=5555
  • Once you expose the deployment a service will be created so run the below command to see the exposed external IP.
    Plain text
    Copy to clipboard
    Open code in new window
    EnlighterJS 3 Syntax Highlighter
    kubectl get services --watch
    kubectl get services --watch
    kubectl get services --watch

  • Now if you try to access the Integration server you will be able to see it is up and running.

Upload file to Cloud storage bucket :


  • Navigate to Cloud Storage and create a bucket.
  • Once the bucket is created, use the upload button and upload the file.

Upload a file to a running pod in GKE :


  • Run the following command to obtain the JWT authentication token, which we will use when uploading a file from a storage bucket to a running pod.
    Plain text
    Copy to clipboard
    Open code in new window
    EnlighterJS 3 Syntax Highlighter
    gcloud auth application-default print-access-token
    gcloud auth application-default print-access-token
    gcloud auth application-default print-access-token
  • Collect the pod name from the workload section of the Kubernetes Engine page.
    Collect pod name
  • Run the below query to get into the pod’s internal directory.
    Plain text
    Copy to clipboard
    Open code in new window
    EnlighterJS 3 Syntax Highlighter
    kubectl exec -it POD-NAME -- /bin/sh
    kubectl exec -it POD-NAME -- /bin/sh
    kubectl exec -it POD-NAME -- /bin/sh
  • Run the below query to get the file from the bucket and put it into the pod directory.
    Plain text
    Copy to clipboard
    Open code in new window
    EnlighterJS 3 Syntax Highlighter
    curl -o /POD-PATH/DEST-FILE-NAME -H "Authorization: Bearer ACCESS_TOKEN" https://storage.googleapis.com/BUCKET-NAME/FILE-NAME
    Example :
    curl -o /opt/softwareag/IntegrationServer/replicate/inbound/WebMethodsDemo.zip -H "Authorization: Bearer ya29.a0AfB_byA1q6YAFpyJj2oan0ss-nu0fT2EG5tqFs0Kz_bwxPmfsqKL2NKwG2iQXfNaB_hr01v-P_qSrRBwaO48sKVOrHst_cFBkzLS8RSh1XHqAnpNG_6J5p0YGQKbecj_Q2wV01JbnOFxyTmb-aNSNdEzc4HqerPqpr5bn3Tjl4j3x1NVAqzGaGqpFS3JZfCF_I6T83NlTEkTIvlgxeZ6IsNO4UTjrtkC8URISpLwfd0CDpiszbZy7DsvN3zvdPshxXRqSbI8Nslf2QAzMktD1LVvkl4bQHatFvTZtQAx4WIYMLZlDs54YFlS-J8LLp7qgHltPQt5JSuttvhLZkjiDLUp0DD7WfEbBSe1SvZovszZEXW87cnNGPZBclIGp0Ya4h-6dhCVijQ5EsOFIqZSye4AYaKZvy0aCgYKAUcSARMSFQHGX2MiaL9_U8pt-HsinI-Gm-0ybQ0422" https://storage.googleapis.com/pod-demo-bucket/WebMethodsDemo.zip
    curl -o /POD-PATH/DEST-FILE-NAME -H "Authorization: Bearer ACCESS_TOKEN" https://storage.googleapis.com/BUCKET-NAME/FILE-NAME Example : curl -o /opt/softwareag/IntegrationServer/replicate/inbound/WebMethodsDemo.zip -H "Authorization: Bearer ya29.a0AfB_byA1q6YAFpyJj2oan0ss-nu0fT2EG5tqFs0Kz_bwxPmfsqKL2NKwG2iQXfNaB_hr01v-P_qSrRBwaO48sKVOrHst_cFBkzLS8RSh1XHqAnpNG_6J5p0YGQKbecj_Q2wV01JbnOFxyTmb-aNSNdEzc4HqerPqpr5bn3Tjl4j3x1NVAqzGaGqpFS3JZfCF_I6T83NlTEkTIvlgxeZ6IsNO4UTjrtkC8URISpLwfd0CDpiszbZy7DsvN3zvdPshxXRqSbI8Nslf2QAzMktD1LVvkl4bQHatFvTZtQAx4WIYMLZlDs54YFlS-J8LLp7qgHltPQt5JSuttvhLZkjiDLUp0DD7WfEbBSe1SvZovszZEXW87cnNGPZBclIGp0Ya4h-6dhCVijQ5EsOFIqZSye4AYaKZvy0aCgYKAUcSARMSFQHGX2MiaL9_U8pt-HsinI-Gm-0ybQ0422" https://storage.googleapis.com/pod-demo-bucket/WebMethodsDemo.zip
    curl -o /POD-PATH/DEST-FILE-NAME -H "Authorization: Bearer ACCESS_TOKEN" https://storage.googleapis.com/BUCKET-NAME/FILE-NAME
    
    Example :
    curl -o /opt/softwareag/IntegrationServer/replicate/inbound/WebMethodsDemo.zip -H "Authorization: Bearer ya29.a0AfB_byA1q6YAFpyJj2oan0ss-nu0fT2EG5tqFs0Kz_bwxPmfsqKL2NKwG2iQXfNaB_hr01v-P_qSrRBwaO48sKVOrHst_cFBkzLS8RSh1XHqAnpNG_6J5p0YGQKbecj_Q2wV01JbnOFxyTmb-aNSNdEzc4HqerPqpr5bn3Tjl4j3x1NVAqzGaGqpFS3JZfCF_I6T83NlTEkTIvlgxeZ6IsNO4UTjrtkC8URISpLwfd0CDpiszbZy7DsvN3zvdPshxXRqSbI8Nslf2QAzMktD1LVvkl4bQHatFvTZtQAx4WIYMLZlDs54YFlS-J8LLp7qgHltPQt5JSuttvhLZkjiDLUp0DD7WfEbBSe1SvZovszZEXW87cnNGPZBclIGp0Ya4h-6dhCVijQ5EsOFIqZSye4AYaKZvy0aCgYKAUcSARMSFQHGX2MiaL9_U8pt-HsinI-Gm-0ybQ0422" https://storage.googleapis.com/pod-demo-bucket/WebMethodsDemo.zip

  • If you run the ‘ls‘ command in the directory where you uploaded the file, you’ll notice that it has been successfully uploaded.
  • Now you can exit the pod shell using the ‘exit‘ command.

Hope you have enjoyed this article and found this useful, Cheers!!

 

Leave a Comment