Using Redis from Python

Once we can access our Python Pod, we can invoke Python interactively and access Redis. Recall that when we created this Pod, we didn’t include any Python libraries for Redis. For this example, we can install them on the fly, but that change will only be relevant for this single Pod, and for the duration of this Pod’s life cycle. If the Pod dies, any changes (such as adding the Redis library) will be lost.

This makes a great tool for interactively and dynamically trying things out, but remember that you will need to incorporate any desired changes back into the process of creating the container as well.

Within the flask Pod, go to the code directory we set up and we can add the Redis library using PIP:

# cd /opt/exampleapp/ ...

Get Kubernetes for Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.