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.
And yeah, try this at home!
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:
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:
Great, we’re settled with access, how do we to add the application?
Developer -> Add menu - don’t be scared from
too many options!
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.
- 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: