Kubernetes For The Real Housewives - How To Easily Host Photoprism Photo/Video Gallery on OpenShift

This post is about opportunity: invest small amount of time and get new skills with real application instance that can do some useful tasks for you or your friends: blog, photo gallery, game server etc.

Kubernetes For The Real Housewives - How To Easily Host Photoprism Photo/Video Gallery on OpenShift
Photo by Growtika / Unsplash

K8S? I still need a gold old shared hosting with PHP and MySQL!

This post is about opportunity: invest small amount of time and get new skills with real application instance that can do some useful tasks for you or your friends: blog, photo gallery, game server etc.

Kubernetes is not designed to compete with shared hosting or DigitalOcean droplets by simplicity, it’s completely different design level. K8S designed to run hundreds and thousands of nodes in production with solid orchestration level: scaling, health checking and automatic rollbacks.

But who said we can’t use this enterprise monster in our own way? Let’s deploy a simple application for fun and profit, as well as cover the Kubernetes basics - the chances to meet K8S somewhere later in your life are high.

Legends about 300 more YAML configs in Kubernetes are not exactly true: you only need to learn the basics keys and K8S editor with powerful linter will do the rest.

Photoprism is chosen as a sample deployment target because it is a popular application for hosting and sharing photos and videos - both public and private, as the user decides.

It’s worth highlighting Photoprism’s core features - just in case you still don’t believe it’s a solid investment:

  • Photoprism handles photo & video raw conversion and saves the originals too.
  • Powerful search filters.
  • Face recogition.
  • Auto classifications based on tags, locations and content.
  • PhotoSync tool supports multimedia backup: smartphone, desktop or NAS - all covered.
  • WebDAV support - easy connection using Nautilus on Linux, Windows Explorer or Apple’s Finder.
  • Independent Big-Corp free development.
Photoprism UI

And yeah, try this at home!

Why OpenShift?

OpenShift, in short, is the Kubernetes boutique - hybrid cloud Platform as a Service of Linux containers. Upstream platform called OKD is open source, the final product deployed on AWS, Azure and Google Cloud.

OpenShift Developer Sandbox provides:

  • Good trial without credit card.
  • Powerful gear: up to 14 instances.
  • Fast connectivity - 1Gbps link.
  • Non-ephemeral storage for application data.
  • Cron jobs, Ingress Controller, Load Balancer and many other tools
  • UI and console access.
  • GitHub integration.
  • Serverless CI/CD pipelines.
  • Functions as a Service (AWS Lambda alternative).

Super short Kubernetes basics - you don’t need to be afraid!

Kubernetes is a cluster manager developed by Google and used to run tons of services. It’s also called ‘k8s’, where 8 is a number of letters in the word “Kubernetes”.

--------------------------------------------------------------
|       |    |             |    |    |    |   |    |         |
|Cluster| -> |Control Plane| -> |Node| -> |Pod| -> |Container|
|       |    |             |    |    |    |   |    |         |
--------------------------------------------------------------
  • Control plane - manager of cluster state, the access point to nodes, pods and containers. Provides access from Admin UI and command line tools.

    • Controller Manager - responsible for controllers, for example the ReplicaSet cares about Pods number to get the job done, how many pods should be active on update or rollback and tons of other options.
    • Scheduler for periodic tasks like Cron jobs.
    • Etcd - distributed key-value store.
    • API server - primary interface to connect all K8S parts to each other.
  • Node - basic building block of K8S applications, the “bricks”.

  • Pod - smallest deployable unit in Kubernetes, it hosts containers and provides shared networking and storage for them.

  • Container - where the application lives, and not limited only for apps: databases, cashes, raw data sets and more.

K8s killer features

  • Self-healing - when crash happens, K8S immediately restarts the container and fires the note to global events.
  • Automated Rollbacks - failed deployment? No tragedy, K8S can load old version and the service will work again.
  • Horizontal scaling - scale up and down, depending on the load - “pay as you go” principle in action

Where to start?

Start from the container, then connect it to other containers or applications (nodes) if you need to. You can use containers from the gigantic library called Docker Hub, build your own, or even modify existing containers - see the small example below:

FROM ubuntu:latest
RUN echo -e "#!/bin/sh\n echo 'Hi there!' " > /usr/bin/welcome.sh
RUN chmod +x /usr/bin/welcome.sh
CMD /usr/bin/welcome.sh

This modification will print “Hi there!” after each start of container.

Deploy our application

Let’s roll! After logging in the OpenShift Developer Sandbox you will see the window like this one:

openshift-1-dashboard.png

Here’s the most important information about the project. Have you read about the control plain above? That’s it. The web interface is big, we won’t cover it completely right now, so let’s stop at the Topology - graphical interface with access to Nodes, Pods and containers:

openshift-2-topology

Great, we’re settled with access, how do we to add the application? Using the Developer -> Add menu - don’t be scared from too many options!

openshift-3-add

We will use the probably easiest way - deploying Docker container from Docker Hub. If you don’t like it - welcome to use another tools:

  • Create applications using samples - Quarkus and Spring Bot for Java applications
  • Helm Chart - deploy with package manager for K8S.
  • Developer Catalog - ready solutions for Node, Go, Ruby, PHP apps and popular databases like MariaDB, MySQL and Postgres.
  • Samples: Nginx, Apache Httpd, .Net 7 and more.
  • Git repository with Dockerfile, Devfile or Builder images
  • Local machine uploads: JAR file or YAML config
  • Serverless functions like AWS Lambda.
  • Pipelines
  • Serverless Eventing

So, we are going to Docker Hub to get the official Photoprism image. The Docker guide also provides useful information. Hit Developer -> Add, pick “Container images”, then type photoprism/photoprism. Let’s fill out the Add form:

  • “Application name” and “Name” will be “photoprism”.
  • “Resource type” - “Deployment”.
  • “Target port” - 2342.
  • “Create a route” - yes.
  • “Advanced options” - “Deployment” - “Environment variables”: set PHOTOPRISM_ADMIN_PASSWORD environment variable to “k8sadmin”.

Then press “Create” button and wait few seconds, the deploy is very fast.

Now you can see the result - our deployed Node with Photoprism application:

The Node

On the right tab is the Pod link, Service with all open ports (2342 is the default port) and Routes - we created them in the previous step. Click on the link below Routes, it will open the website will “Login” and “Password” forms. You should login as user “Admin” and password “k8sadmin” - we used the PHOTOPRISM_ADMIN_PASSWORD environment variable for the password, for sure you need something more complex as password.

Photoprism UI

And yeah - we’re in!!!🎆 We have our instance up and running and can upload photos and videos!

Data

All set, just one little nuance - everything will be deleted after the first run. To keep it, we need to add two volumes:

  • /photoprism/storage - contains SQLite DB, config, cache, thumbnail and sidecar files are saved in the storage folder.

  • /photoprism/originals - contains the original raw images and videos.

The optional volume /protoprism/import- this is nothing else than import folder, just copy any multimedia there and Photoprism will automatically import all content and exclude duplicates.

How to add volumes to our instance? Super easy, just two steps:

  • Create the Volume Claim with name photoprism-storage-20GB and the size depends from the media library.
  • Click on the topology app icon, select “Add storage -> pick the Volume Claim” and add mount points: /photoprism/storage, /photoprism/originals or the optional /protoprism/import.

Routes - expose more ports

Photoprism supports more ports than the default 2342:

  • 2443 - default TLS port.
  • 2343 - Acceptance Test HTTP port
  • 40000 - Go Debugger port

If you need to access any of them from otside the cluster, let’s use the Routes. In the UI switch to the Administator tab, then click to “Networking -> Routes -> Add route”:

  • Name: “port2343”
  • Hostname: empty, it will be generated
  • Path: “/”
  • Target port: 2443
  • Secure route: no

Then click “Create” button and you’ll get a generated domain name, now it’s possible to access the port using “domain_name:2443”.

How to impove this instance?

  • MySQL database - for big photo collections like 100 GB and more Sqlite will be slow due to intensive read/write operations.
  • Allocate more resources with auto scaling.
  • Advanced monitoring with app restarts and notifications.
  • Automated backups.
  • Load balancer.
  • Add network security policies for better security.
  • Adding new user with access to this app only will also improve security.

The end on the high note

Hope you enjoyed this post about Kubernetes and if want more content or can add some useful tips or tricks - write it all in the comments below.

Read more