Deploy from Docker Compose using Kompose
Kompose is a simple utility you can use to convert your existing docker-compose
files into Kubernetes Workloads. In this guide, we'll walk you through using the
kompose
to convert a NextCloud Compose file to a full Kubernetes workload.
Prerequisites
- A Namespace in a Subkube Project
- Kubectl
- Optional: Kompose (we'll install kompose as part of this guide)
Steps
Installing Kompose
On Linux or macOS, installing compose is easy as:
1 2 3 4 5 6 7 8 |
|
More installation instructions, including for windows, can be found on the kompose.io/installation page
Inspecting our Compose file
For this guide, we will be using the following docker-compose.yaml
file to
deploy a NextCloud instance, including a MariaDB and Nginx instance:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
|
As you can see it is using the nextcloud:fpm
image to run the NextCloud php
application, and an nginxinc/nginx-unprivileged
image to run Nginx as non-root
on port 8080
.
Running the Conversion
The kompose
utilty has various capabilities, including the option to generate
a Helm Chart from a Compose file, create Openshift-compliant resources,
or create ReplicationController or DaemonSet workloads.
In this example, we will use the --out
option to tell kompose
to put the
generated manifests in the output
directory, which we have to create manually
before running kompose
:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
As you can see, Kompose has created both a Deployment and a Service for each
entry in our Compose file. You also see a warning about the nginx.conf
file
used for the Nginx web
container, which we will address in the upcoming section.
Updating the generated resources
Before we can apply these resources, we want to make some changes.
Add our Configuration
We use a custom Nginx Configuration for the nginx
container serving as HTTP
proxy to Nextloud's php-fpm
app container. As you cannot simply mount a file
inside a container on Kubernetes, we need to convert the nginx.conf
file to
a ConfigMap. Luckily, kubectl
can do this largely for us:
1 2 3 4 |
|
Now we should replace the generated web-claim0
PersistentVolumeClaim with our
ConfigMap:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
|
Do not forget to remove the unneeded web-claim0
PersistentVolumeClaim manifest:
1 |
|
Use a Secret
In our docker-compose.yaml
, we specified the MySQL connection parameters directly
as environment variables to the container. In Kubernetes, we use Secrets for this
sort of thing. Let's setup a secret we can use for our MariaDB deployment, using kubectl
:
1 2 3 4 5 6 |
|
Inside our Deployments, we can use the envFrom
directive to tell
Kubernetes which Secret to use for the app
and db
workloads:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
|
Setting Resources & Security Contexts
As with any workload running on Subkube, we should set appropriate resources for the deployments, as well as securityContexts.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
|
Apply and Verify
After we have made these changes, we can deploy the resources:
1 2 3 4 5 6 7 8 9 10 11 |
|
We can monitor our Deployments' to see them progressing:
1 |
|
Once everything is ready, we can setup a port-forward
to access NextCloud and
trigger the setup process, by creating an Admin user.
1 |
|