Accessing EODATA from Kubernetes Pods in Creodias using boto3

While using Kubernetes on Creodias clouds, you might soon want to access EODATA satellite image repository.

A common use case can be e.g. batch job processing, where Kubernetes pods initiate download of EODATA images to process them further.

This article explains how EODATA access is implemented on OpenStack Magnum and is using Python’s library boto3 to access EODATA from Kubernetes pods. Docker and DockerHub will serve to containerize and deploy the application accessing EODATA.

Prerequisites

No. 1 Account

You need a Creodias hosting account with access to the Horizon interface: https://horizon.cloudferro.com/auth/login/?next=/.

No. 2 Kubernetes cluster with access to EODATA

A Kubernetes cluster on Creodias created with option “EODATA access enabled”. Refer to the knowledge base article How to Create a Kubernetes Cluster Using Creodias OpenStack Magnum.

No. 3 Familiarity with kubectl

Use a Bash terminal on the machine where you configured kubectl for this cluster. You need permission to create Secrets and pods, read pod logs and execute commands in the example namespace eodata-demo. If your administrator assigned an existing namespace, use its name in the commands and pod manifest instead.

For further instructions refer to How To Access Kubernetes Cluster Post Deployment Using Kubectl On Creodias OpenStack Magnum

No. 4 Understanding how boto3 library accesses EODATA

To understand how to access EODATA without Kubernetes, study How to access EODATA using boto3 on Creodias. The article you are reading now applies that method to a Kubernetes environment.

Obtain your EODATA access key and secret key using How to get credentials used for accessing EODATA on a cloud VM on Creodias.

To create a separate pair in the dashboard, follow Obtain S3 credentials for EODATA Access from Creodias Dashboard.

WAW3-1 also requires a valid key pair. Private Object Storage EC2 credentials are separate. The example downloads a PNG object; if that object is no longer available, choose another PNG using the boto3 guide above.

No. 5 Docker installed on your machine

See How to install and use Docker on Ubuntu 24.04.

No. 6 An account in DockerHub

An account in DockerHub. You can use other image registries, but that is beyond the scope of this article. The cluster must be able to pull the image; this example uses a public repository. For a private repository, prepare an imagePullSecret using the Kubernetes instructions for pulling an image from a private registry.

What We Are Going To Do

  • Provide background information on using EODATA on Magnum

  • Prepare Docker image of an application accessing EODATA with boto3

  • Build Docker image and push it to DockerHub

  • Create an EODATA Secret, launch a Kubernetes pod and verify EODATA access

Step 1 Create Kubernetes cluster with EODATA

On Creodias , the eodata network or the project’s eodata_ network provides access to EODATA. When creating the virtual machines used by a Magnum cluster, this network can be attached to the worker nodes. If you already have the cluster from Prerequisite No. 2, check its network connections as described below.

Since a Kubernetes cluster built on Magnum is created from those same VMs, you can provide access to EODATA to each worker node in the cluster. Use commands Container Infra → Clusters → Create Cluster to start creation of a cluster and tick the box “EODATA access enabled”.

../_images/marine-study-create2.png

After the creation of the cluster is finished, check whether the nodes were properly connected to EODATA. Run Compute → Instances and verify that the IP address of your worker nodes is on EODATA network. In the image below, marine-study is the name of the cluster while eodata_00341_3 will be the name of EODATA network:

../_images/marine_study.png

Two worker nodes are linked to eodata_ network while the master node is not. That is because Master Nodes manage the cluster and are not provisioned with access to EODATA.

Here is how you can deliver the software for EODATA access through a Docker image.

Step 2 Prepare the application’s Docker image

boto3 is a standard Python library for interacting with S3 object storage. Strategically speaking, the container you are building must contain the following elements:

  • Python and boto3 installed

  • correct endpoints for accessing EODATA

  • S3 credentials supplied at runtime through a Kubernetes Secret.

With the following four files, you can “dockerize” your application, that is, build its Docker image and send it to DockerHub:

  • a concrete Python file with application code (app.py in our case)

  • requirements.txt file that specifies the dependencies for boto3 library

  • Dockerfile that provides instructions for the container build

  • .dockerignore to keep credentials and other unrelated files out of the image

Dockerfile is based on Python 3.12, will install boto3 and then run the application. In application code, you download a sample image and make the container wait for 300 seconds. You only need a few seconds to verify that the image was properly downloaded, so five minutes will be more than enough. Create the following four files and place them into the same directory:

app.py

Boto3 reads AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY from the container environment. The pod receives these values from the Secret in Step 4; do not put the keys in the application files.

import os
import time

import boto3
from botocore.config import Config


def main():
    required = (
        "AWS_ACCESS_KEY_ID",
        "AWS_SECRET_ACCESS_KEY",
        "EODATA_ENDPOINT",
        "EODATA_KEY",
    )
    missing = [name for name in required if not os.environ.get(name)]
    if missing:
        raise RuntimeError("Missing environment variables: " + ", ".join(missing))

    s3 = boto3.client(
        "s3",
        endpoint_url=os.environ["EODATA_ENDPOINT"],
        config=Config(signature_version="s3v4", s3={"addressing_style": "path"}),
    )
    s3.download_file("eodata", os.environ["EODATA_KEY"], "/app/image.png")
    print("Downloaded /app/image.png", flush=True)
    # Allow time to inspect or copy the file before this demonstration pod exits.
    time.sleep(300)


if __name__ == "__main__":
    main()

Download: app.py.

requirements.txt

boto3>=1.34,<2

Dockerfile

FROM python:3.12-slim

WORKDIR /app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY app.py ./
CMD ["python", "app.py"]

.dockerignore

*
!Dockerfile
!requirements.txt
!app.py

Step 3 Build the app’s image and push to DockerHub

To build a Docker image and send it to DockerHub, run the following command from the directory where the files are placed (replace YOUR_DOCKERHUB_USER with your Docker Hub account name):

Note

Depending on your setup, you might need to prefix the Docker commands with sudo.

docker build -t YOUR_DOCKERHUB_USER/eodata-demo:v1 .

Ensure that you are logged into your DockerHub:

docker login

Then push the image to DockerHub (the repository will get created in DockerHub if it does not exist):

docker push YOUR_DOCKERHUB_USER/eodata-demo:v1

You can verify that the image is pushed by checking in DockerHub web GUI.

../_images/marine_study_public.png

In this image, the repository is already public. Use the public repository or the private-registry access prepared in Prerequisite No. 6. The pod manifest must use the same image name and tag that you pushed.

Step 4 Deploy the application on Kubernetes

You have created the image and pushed it to DockerHub. On the machine where kubectl is configured, check the selected cluster and create the example namespace:

kubectl config current-context
kubectl create namespace eodata-demo

If the namespace already exists, continue using it. Create the credentials Secret and deploy the pod in that same namespace.

Create the EODATA Secret

Save the following helper as create_eodata_secret.sh on the machine where kubectl is configured. It prompts for the access key and secret key without displaying them, writes a private temporary file outside the Docker build directory and submits that file to Kubernetes. The temporary file is removed when the helper exits.

#!/usr/bin/env bash
# Run on the machine where kubectl is configured, outside the image build.
set +x
set -euo pipefail
umask 077

namespace="${1:-eodata-demo}"
credentials_file="$(mktemp "${TMPDIR:-/tmp}/eodata-credentials.XXXXXX")"
trap 'rm -f -- "$credentials_file"' EXIT
trap 'exit 130' INT
trap 'exit 143' TERM

IFS= read -r -s -p 'EODATA access key: ' access_key
printf '\n'
IFS= read -r -s -p 'EODATA secret key: ' secret_key
printf '\n'

if [[ -z "$access_key" || -z "$secret_key" ||
      "$access_key" =~ [[:space:]] || "$secret_key" =~ [[:space:]] ]]; then
    printf 'Both keys must be nonempty and contain no whitespace. Copy them again.\n' >&2
    exit 1
fi

printf 'AWS_ACCESS_KEY_ID=%s\nAWS_SECRET_ACCESS_KEY=%s\n' \
    "$access_key" "$secret_key" > "$credentials_file"
unset access_key secret_key

kubectl -n "$namespace" create secret generic eodata-credentials \
    --from-env-file="$credentials_file"

Download: create_eodata_secret.sh.

Run the helper and paste each key directly from the dashboard or credentials file:

bash create_eodata_secret.sh eodata-demo

On success, kubectl reports:

secret/eodata-credentials created

Confirm that the Secret exists without printing its values:

kubectl -n eodata-demo describe secret eodata-credentials

The Data section should list AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY, with a nonzero byte count for each. The Secret and pod must be in the same namespace. Kubernetes permissions control who can read the Secret.

If kubectl reports AlreadyExists, the helper leaves the existing Secret unchanged. Reuse that Secret if it contains the intended pair. If you need to replace its credentials, follow your namespace’s credential-update procedure and recreate the demonstration pod so that it receives the new environment values.

Deploy the pod

Save the following manifest as eodata-pod.yaml. Replace YOUR_DOCKERHUB_USER with the account used when pushing the image. The secretKeyRef entries refer to keys in the Secret; they contain no credential values.

apiVersion: v1
kind: Pod
metadata:
  name: eodata-demo
  namespace: eodata-demo
spec:
  restartPolicy: Never
  containers:
    - name: downloader
      image: YOUR_DOCKERHUB_USER/eodata-demo:v1
      env:
        - name: AWS_ACCESS_KEY_ID
          valueFrom:
            secretKeyRef:
              name: eodata-credentials
              key: AWS_ACCESS_KEY_ID
        - name: AWS_SECRET_ACCESS_KEY
          valueFrom:
            secretKeyRef:
              name: eodata-credentials
              key: AWS_SECRET_ACCESS_KEY
        - name: AWS_DEFAULT_REGION
          value: "us-east-1"
        - name: EODATA_ENDPOINT
          value: "https://eodata.cloudferro.com"
        - name: EODATA_KEY
          value: "Landsat-5/TM/L1T/2011/11/11/LS05_RKSE_TM__GTC_1P_20111111T093819_20111111T093847_147313_0191_0025_1E1E/LS05_RKSE_TM__GTC_1P_20111111T093819_20111111T093847_147313_0191_0025_1E1E.BP.PNG"

Apply the manifest and check the pod:

kubectl apply -f eodata-pod.yaml
kubectl -n eodata-demo get pod eodata-demo
kubectl -n eodata-demo logs -f eodata-demo

Running the pod starts the containerized Python application. After the download succeeds, the logs show Downloaded /app/image.png. The application waits five minutes before exiting, so you can enter the container and inspect the file:

kubectl -n eodata-demo exec --tty --stdin eodata-demo -- sh

That opens a shell inside the container. Navigate to /app and list the downloaded file:

cd /app
ls -lh image.png
../_images/downloaded_image.png

What To Do Next

Following the guidelines in this article, you can implement more complex scenarios, for instance, by using deployments or jobs instead of pods.

This example already supplies the S3 credentials through a Kubernetes Secret. For a secrets registry such as HashiCorp Vault, see Installing HashiCorp Vault on Creodias Magnum.