Docker-compose Rancher Kubernetes migration (Microservice persistence)

Introduction

Instead of running the docker containers through docker-compose, a popular method used to simply said composing an entire docker cluster full of microservices, I instead opted to deploy it on Rancher. In Rancher, the containers are pulled from Docker.io (in my case) & built using the yaml configuration.

Implementation

If we look at the docker-compose file, you can see that I start set up mySQL in the cluster. Since, previously, I had the connection string to the database pointed at my localhost, this migration would mean that couldn’t work.

GameService docker-compose.yml
version: "3.8"
services:
mysqldb:
    image: mysql:5.7
    restart: unless-stopped
    env_file: .env
    environment:
    - MYSQL_ROOT_PASSWORD=$MYSQLDB_ROOT_PASSWORD
    - MYSQL_DATABASE=$MYSQLDB_DATABASE
    ports:
    - 3306:3306
    volumes:
    - db:/var/lib/mysql
gameService:
    depends_on:
    - mysqldb
    build: ./gameService/
    image: ramses-gameservice:latest
    container_name: ram
    restart: on-failure
    env_file: .env
    ports:
    - 9521:9521
    environment:
    SPRING_APPLICATION_JSON: '{
        "spring.datasource.url"  : "jdbc:mysql://mysqldb:$MYSQLDB_DOCKER_PORT/$MYSQLDB_DATABASE?useSSL=false",
        "spring.datasource.username" : "$MYSQLDB_USER",
        "spring.datasource.password" : "$MYSQLDB_ROOT_PASSWORD",
        "spring.jpa.properties.hibernate.dialect" : "org.hibernate.dialect.MySQL5InnoDBDialect",
        "spring.jpa.hibernate.ddl-auto" : "update"
    }'

Visit the mySQL page more about the DB implementation. I reconfigured my application.properties in order to meet adjust the location of the sql server as such:

spring.datasource.url = jdbc:mysql://10.0.0.34:3306/ramses_game?allowPublicKeyRetrieval=true&useSSL=false&useJDBCCompliantTimezoneShift=true&useJDBCCompliantTimezoneShift=true

More specifically: allowPublicKeyRetrieval=true& was required as an added parameter to integrate it into my own cloud(Rancher).

Through Rancher I created the configuration through the interface, but looking at the YAML the differences between kubernetes config and docker compose can be highlighted.

apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
    deployment.kubernetes.io/revision: "11"
    field.cattle.io/publicEndpoints: '[{"addresses":["10.0.0.42"],"port":80,"protocol":"HTTP","serviceName":"ramses:gameservice","ingressName":"ramses:gameservice","hostname":"api.oksolution.nl","path":"/game","allNodes":false}]'
creationTimestamp: "2022-05-17T10:55:55Z"
generation: 58
labels:
    workload.user.cattle.io/workloadselector: apps.deployment-ramses-gameservice
managedFields:
- apiVersion: apps/v1
    fieldsType: FieldsV1
    fieldsV1:
    f:spec:
        f:replicas: {}
    manager: k3s
    operation: Update
    subresource: scale
- apiVersion: apps/v1
    fieldsType: FieldsV1
    fieldsV1:
    f:metadata:
        f:annotations:
        f:field.cattle.io/publicEndpoints: {}
        f:labels:
        .: {}
        f:workload.user.cattle.io/workloadselector: {}
    f:spec:
        f:progressDeadlineSeconds: {}
        f:revisionHistoryLimit: {}
        f:selector: {}
        f:strategy:
        f:rollingUpdate:
            .: {}
            f:maxSurge: {}
            f:maxUnavailable: {}
        f:type: {}
        f:template:
        f:metadata:
            f:annotations:
            .: {}
            f:cattle.io/timestamp: {}
            f:labels:
            .: {}
            f:workload.user.cattle.io/workloadselector: {}
        f:spec:
            f:affinity: {}
            f:containers:
            k:{"name":"gameservice"}:
                .: {}
                f:image: {}
                f:imagePullPolicy: {}
                f:name: {}
                f:ports:
                .: {}
                k:{"containerPort":9521,"protocol":"TCP"}:
                    .: {}
                    f:containerPort: {}
                    f:name: {}
                    f:protocol: {}
                f:resources:
                .: {}
                f:limits:
                    .: {}
                    f:cpu: {}
                f:requests:
                    .: {}
                    f:cpu: {}
                f:terminationMessagePath: {}
                f:terminationMessagePolicy: {}
            f:dnsConfig: {}
            f:dnsPolicy: {}
            f:imagePullSecrets:
            .: {}
            k:{"name":"iosecret"}: {}
            f:restartPolicy: {}
            f:schedulerName: {}
            f:securityContext: {}
            f:terminationGracePeriodSeconds: {}
    manager: rancher
    operation: Update
    time: "2022-05-26T13:36:55Z"
- apiVersion: apps/v1
    fieldsType: FieldsV1
    fieldsV1:
    f:metadata:
        f:annotations:
        .: {}
        f:deployment.kubernetes.io/revision: {}
    f:status:
        f:availableReplicas: {}
        f:conditions:
        .: {}
        k:{"type":"Available"}:
            .: {}
            f:lastTransitionTime: {}
            f:lastUpdateTime: {}
            f:message: {}
            f:reason: {}
            f:status: {}
            f:type: {}
        k:{"type":"Progressing"}:
            .: {}
            f:lastTransitionTime: {}
            f:lastUpdateTime: {}
            f:message: {}
            f:reason: {}
            f:status: {}
            f:type: {}
        f:observedGeneration: {}
        f:readyReplicas: {}
        f:replicas: {}
        f:updatedReplicas: {}
    manager: k3s
    operation: Update
    subresource: status
    time: "2022-05-26T14:22:10Z"
name: gameservice
namespace: ramses
resourceVersion: "890104"
uid: 49b52250-2859-4098-8aee-a368ec54dd19
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 10
selector:
    matchLabels:
    workload.user.cattle.io/workloadselector: apps.deployment-ramses-gameservice
strategy:
    rollingUpdate:
    maxSurge: 25%
    maxUnavailable: 25%
    type: RollingUpdate
template:
    metadata:
    annotations:
        cattle.io/timestamp: "2022-05-26T13:49:35Z"
    creationTimestamp: null
    labels:
        workload.user.cattle.io/workloadselector: apps.deployment-ramses-gameservice
    spec:
    affinity: {}
    containers:
    - image: badministrator/ramses:gameservice
        imagePullPolicy: Always
        name: gameservice
        ports:
        - containerPort: 9521
        name: api
        protocol: TCP
        resources:
        limits:
            cpu: 130m
        requests:
            cpu: 50m
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
    dnsConfig: {}
    dnsPolicy: Default
    imagePullSecrets:
    - name: iosecret
    restartPolicy: Always
    schedulerName: default-scheduler
    securityContext: {}
    terminationGracePeriodSeconds: 30
status:
availableReplicas: 1
conditions:
- lastTransitionTime: "2022-05-26T13:37:06Z"
    lastUpdateTime: "2022-05-26T14:10:19Z"
    message: ReplicaSet "gameservice-68bbc468f7" has successfully progressed.
    reason: NewReplicaSetAvailable
    status: "True"
    type: Progressing
- lastTransitionTime: "2022-05-26T14:22:10Z"
    lastUpdateTime: "2022-05-26T14:22:10Z"
    message: Deployment has minimum availability.
    reason: MinimumReplicasAvailable
    status: "True"
    type: Available
observedGeneration: 58
readyReplicas: 1
replicas: 1
updatedReplicas: 1