Kubernetes with Pimcore
What is Kubernetes?
Containers have become indispensable since the introduction of Docker in 2013. Containers ensure the separation and management of different software resources. Everything the application needs is located in the container and remains securely and reliably. Among other things, this allows applications with different PHP versions to run on one computer without version conflicts. This allows workloads to be parallelized and ensures that all instances have installed the same software with the same dependencies. In addition, the images can be easily transferred from computer to computer and a reproducible software package can be created.
To make the management of these containers simple and traceable, Google developed Kubernetes in 2014.
Kubernetes is a system for automatically orchestrating, scaling and managing containerized applications on distributed hosts.
Kubernetes manages the deployment, scaling and availability of containers automatically on a cluster of servers. It coordinates the computing, networking and storage infrastructure on behalf of user workloads.
Distributing the containers across multiple nodes ensures high availability and resilience. Horizontal as well as vertical scaling is possible. In addition, compute resources are used more efficiently. (e.g. idle staging or dev systems).
How does Kubernetes work?
Kubernetes is an orchestration system. This means it is not responsible for creating containers but for managing them. The architecture consists of a clear hierarchy:
Container: A container contains an application and software environment.
Pod: This unit groups container that needs to work together for an application (e.g., NGINX+PHP).
Node: One or more pods run on a node.
Cluster: Multiple nodes are grouped together to form a cluster.
Kubernetes is based on an "operator" and "worker" principle. Workers are the nodes of the system that are to be controlled. They are under the management of the operator and Kubernetes distributes the workloads to all available workers.
The operator's tasks are to monitor the cluster. If a node fails, Kubernetes must distribute the workloads to other nodes in the cluster. If a container becomes "unhealthy", Kubernetes stops it and restarts it.
Kubernetes works with declarative configuration files where the "target" state of the application is described. If the ACTUAL state deviates from the TARGET state, Kubernetes tries to solve the problem automatically. This is also referred to as "self-healing".
How does Kubernetes help with Pimcore?
Due to the high degree of automation that Kubernetes offers, Pimcore can be used more efficiently and scalably. By evaluating certain metrics, such as CPU or RAM usage, Kubernetes can scale Pimcore up or down automatically. Containerisation makes it easier to perform major upgrades of Pimcore or PHP versions. Likewise, staging systems or DEV systems run less idle. These can be shut down at certain times through automation to reduce resources and costs.
A cluster can also run workloads of different types. A cluster can run Pimcore with MySQL and Redis. As well as Pimcore independent containers such as Prometheus for monitoring or PDFReactor for PDF document creation.
Cloud - GCP
We use Google Cloud Platform as the cloud provider for our managed Kubernetes cluster. The cloud offers exciting solutions here for simplified management of Kubernetes.
For example, Google Kubernetes Engine with Config Connector allows the creation of Google resources, such as SQL instances or cloud storage with custom resource definitions from within Kubernetes. So the team can request and manage cloud resources they need declaratively with Kubernetes resources.
Specifically, we use a managed cloud SQL instance for the database for Pimcore. GCP, therefore, takes care of the servicing, backup and availability of the database server. Likewise, scaling within seconds is possible with it. As a Pimcore Gold Partner, this allows us to focus more on Pimcore projects than Pimcore hosting.
As storage for Pimcore assets, versions, or similar, we use cloud storage. Google's de-facto pando for S3. Cloud storage gives us theoretically infinite capacity and infinite scaling. We don't have to worry about providing or backing up storage solutions. Connecting to cloud storage with Pimcore X is a simple Symfony config.
A Demo Repository can be found here: https://github.com/cors-gmbh/pimcore-k8s-demo
Want to submit a guest post to Pimcore's Blog?
Submit a guest post and benefit from our network! With our newsletter, we reach more than 5 000 subscribers and attract more than 50 000 monthly visitors to our website, and we're always looking for more brilliant contributors to join our ranks. Contact us.