Update Servers/Containerization/Kubernetes/Migrating Docker-Compose.yml to k8s.md
All checks were successful
GitOps Automatic Deployment / GitOps Automatic Deployment (push) Successful in 8s
All checks were successful
GitOps Automatic Deployment / GitOps Automatic Deployment (push) Successful in 8s
This commit is contained in:
@@ -4,6 +4,8 @@ You may be comfortable operating with Portainer or `docker-compose`, but there c
|
|||||||
!!! info "RKE2 Cluster Deployment"
|
!!! info "RKE2 Cluster Deployment"
|
||||||
This document assumes that you have an existing Rancher RKE2 cluster deployed. If not, you can deploy one following the [Deploy RKE2 Cluster](https://docs.bunny-lab.io/Servers/Containerization/Kubernetes/Deployment/Rancher RKE2/) documentation.
|
This document assumes that you have an existing Rancher RKE2 cluster deployed. If not, you can deploy one following the [Deploy RKE2 Cluster](https://docs.bunny-lab.io/Servers/Containerization/Kubernetes/Deployment/Rancher RKE2/) documentation.
|
||||||
|
|
||||||
|
We also assume that the cluster name within Rancher RKE2 is named `local`, which is the default cluster name when setting up a Kubernetes Cluster in the way seen in the above documentation.
|
||||||
|
|
||||||
## Installing Kompose
|
## Installing Kompose
|
||||||
The first step involves downloading Kompose from https://kompose.io/installation. Once you have it downloaded and installed onto your environment of choice, save a copy of your `docker-compose.yml` file somewhere on-disk, then open up a terminal and run the following command:
|
The first step involves downloading Kompose from https://kompose.io/installation. Once you have it downloaded and installed onto your environment of choice, save a copy of your `docker-compose.yml` file somewhere on-disk, then open up a terminal and run the following command:
|
||||||
|
|
||||||
@@ -54,7 +56,7 @@ This will attempt to convert the `docker-compose.yml` file into a Kubernetes man
|
|||||||
kind: Service
|
kind: Service
|
||||||
metadata:
|
metadata:
|
||||||
annotations:
|
annotations:
|
||||||
kompose.cmd: C:\ProgramData\chocolatey\lib\kubernetes-kompose\tools\kompose.exe --file ntfy.yaml convert --stdout
|
kompose.cmd: C:\ProgramData\chocolatey\lib\kubernetes-kompose\tools\kompose.exe --file ntfy-k8s.yaml convert --stdout
|
||||||
kompose.version: 1.37.0 (fb0539e64)
|
kompose.version: 1.37.0 (fb0539e64)
|
||||||
labels:
|
labels:
|
||||||
io.kompose.service: ntfy
|
io.kompose.service: ntfy
|
||||||
@@ -72,7 +74,7 @@ This will attempt to convert the `docker-compose.yml` file into a Kubernetes man
|
|||||||
kind: Deployment
|
kind: Deployment
|
||||||
metadata:
|
metadata:
|
||||||
annotations:
|
annotations:
|
||||||
kompose.cmd: C:\ProgramData\chocolatey\lib\kubernetes-kompose\tools\kompose.exe --file ntfy.yaml convert --stdout
|
kompose.cmd: C:\ProgramData\chocolatey\lib\kubernetes-kompose\tools\kompose.exe --file ntfy-k8s.yaml convert --stdout
|
||||||
kompose.version: 1.37.0 (fb0539e64)
|
kompose.version: 1.37.0 (fb0539e64)
|
||||||
labels:
|
labels:
|
||||||
io.kompose.service: ntfy
|
io.kompose.service: ntfy
|
||||||
@@ -87,7 +89,7 @@ This will attempt to convert the `docker-compose.yml` file into a Kubernetes man
|
|||||||
template:
|
template:
|
||||||
metadata:
|
metadata:
|
||||||
annotations:
|
annotations:
|
||||||
kompose.cmd: C:\ProgramData\chocolatey\lib\kubernetes-kompose\tools\kompose.exe --file ntfy.yaml convert --stdout
|
kompose.cmd: C:\ProgramData\chocolatey\lib\kubernetes-kompose\tools\kompose.exe --file ntfy-k8s.yaml convert --stdout
|
||||||
kompose.version: 1.37.0 (fb0539e64)
|
kompose.version: 1.37.0 (fb0539e64)
|
||||||
labels:
|
labels:
|
||||||
io.kompose.service: ntfy
|
io.kompose.service: ntfy
|
||||||
@@ -161,7 +163,7 @@ At this point, you need to import the yaml file you created into the Kubernetes
|
|||||||
### Create a Project
|
### Create a Project
|
||||||
The purpose of the project is to logically organize your services together. This can be something like `Home Automation`, `Log Analysis Systems`, `Network Tools`, etc. You can do this by logging into your Rancher RKE2 cluster (e.g. https://rke2-cluster.bunny-lab.io). This Project name is unique to Rancher and purely used for organizational purposes and does not affect the namespaces / containers in any way.
|
The purpose of the project is to logically organize your services together. This can be something like `Home Automation`, `Log Analysis Systems`, `Network Tools`, etc. You can do this by logging into your Rancher RKE2 cluster (e.g. https://rke2-cluster.bunny-lab.io). This Project name is unique to Rancher and purely used for organizational purposes and does not affect the namespaces / containers in any way.
|
||||||
|
|
||||||
- Navigate to: **Clusters > `local` > Projects/Namespaces > "Create Project"**
|
- Navigate to: **Clusters > `local` > Cluster > Projects/Namespaces > "Create Project"**
|
||||||
- **Name**: <Friendly Name> (e.g. `Home Automation`)
|
- **Name**: <Friendly Name> (e.g. `Home Automation`)
|
||||||
- **Description**: <Useful Description for the Group of Services> (e.g. `Various services that automate things within Bunny Lab`)
|
- **Description**: <Useful Description for the Group of Services> (e.g. `Various services that automate things within Bunny Lab`)
|
||||||
- Click the "**Create**" button
|
- Click the "**Create**" button
|
||||||
@@ -169,7 +171,45 @@ The purpose of the project is to logically organize your services together. Thi
|
|||||||
### Create a Namespace within the Project
|
### Create a Namespace within the Project
|
||||||
At this point, we need to create a namespace. This basically isolates the networking, credentials, secrets, and storage between the services/stacks. This ensures that if someone exploits one of your services, they will not be able to laterally move into another service within the same Kubernetes cluster.
|
At this point, we need to create a namespace. This basically isolates the networking, credentials, secrets, and storage between the services/stacks. This ensures that if someone exploits one of your services, they will not be able to laterally move into another service within the same Kubernetes cluster.
|
||||||
|
|
||||||
- Navigate to: **Clusters > `local` > Projects/Namespaces > <ProjectName> > "Create Namespace"**
|
- Navigate to: **Clusters > `local` > Cluster > Projects/Namespaces > <ProjectName> > "Create Namespace"**
|
||||||
- The name for the namespace should be named based on its operational-context, such as `prod-ntfy` or `dev-ntfy`.
|
- The name for the namespace should be named based on its operational-context, such as `prod-ntfy` or `dev-ntfy`.
|
||||||
|
|
||||||
|
### Import Converted YAML Manifest into Namespace
|
||||||
|
At this point, we can now proceed to import the YAML file we generated in the beginning of this document.
|
||||||
|
|
||||||
|
- Navigate to: **Clusters > `local` > Cluster > Projects/Namespaces**
|
||||||
|
- At the top-right of the screen will be an upload / up-arrow button with tooltip text stating "Import YAML" > Click on this button
|
||||||
|
- Click the "**Read from File**" button
|
||||||
|
- Navigate to your `ntfy-k8s.yaml` file. (Name will differ from your actual converted file) > then click the "**Open**" button.
|
||||||
|
- On the top-right of the dialog box will be a "**Default Namespace**" dropdown menu, select the `prod-ntfy` namespace we created earlier.
|
||||||
|
- Click the blue "**Import** button at the bottom of the dialog box.
|
||||||
|
|
||||||
|
!!! warning "Be Patient"
|
||||||
|
This part of the process can take a while depending on the container stack and complexity of the service. It has to download container images and deploy them into newly spun-up pods within Kubernetes. Just be patient and click on the `prod-ntfy` namespace, then look at the "**Workloads**" tab to see if the "ntfy" service exists and is Active, then you can move onto the next step.
|
||||||
|
|
||||||
|
### Configuring Ingress
|
||||||
|
This final step within Kubernetes itself involves reconfiguring the container to list via a "NodePort" instead of "ClusterIP". Don't worry, you do not have to mangle with the ports that the container uses, this is entirely within Kubernetes itself and does not make changes to the original `docker-compose.yml` ports of the container(s) you imported.
|
||||||
|
|
||||||
|
- Navigate to: **Clusters > `local` > Service Discovery > Services > ntfy**
|
||||||
|
- On the top-right, click on the blue "**Show Configuration**" button
|
||||||
|
- On the bottom-right, click the blue "**Edit Config**" button
|
||||||
|
- On the bottom-right, click the "**Edit as YAML**" button
|
||||||
|
- Within the yaml editor, you will see a section named `spec:`, within that section is a subsection named `type:`. You will see a value of `type: ClusterIP` > You want to change that to `type: NodePort`
|
||||||
|
- On the bottom-right, click the blue "**Save**" button and wait for the process to finish.
|
||||||
|
- On the new page that appears, click on the `ntfy` service again
|
||||||
|
- Click on the "**Ports**" tab
|
||||||
|
- You will see a column of the table labeled "Node Port" with a number in the 30,000s such as `30996`. This will be important for later.
|
||||||
|
|
||||||
|
!!! success "Verifying Access Before Configuring Reverse Proxy"
|
||||||
|
At this point, you will want to verify that you can access the service via the cluster node IP addresses such as the examples seen below, all of the cluster nodes should route the traffic to the container's service and will be used for load-balancing later in the reverse proxy configuration file.
|
||||||
|
|
||||||
|
- http://192.168.3.69:30996
|
||||||
|
- http://192.168.3.70:30996
|
||||||
|
- http://192.168.3.71:30996
|
||||||
|
- http://192.168.3.72:30996
|
||||||
|
|
||||||
|
## Configuring Reverse Proxy
|
||||||
|
If you were able to successfully verify access to the service when talking to it directly via one of the cluster node IP addresses with its given Node Port port number, then you can proceed to creating a reverse proxy configuration file for the service. This will be very similar to the original `docker-compose.yml` version of the reverse proxy configuration file, but with additional IP addresses to load-balance across the Kubernetes cluster nodes.
|
||||||
|
|
||||||
|
!!! info "Considerations"
|
||||||
|
This section of the document
|
||||||
Reference in New Issue
Block a user