SAFplus deployment with Kubernetes


Introduction

You may know Virtual Machines (VM) where you can deploy and run your applications, especially when you want to have an environment to test. But with a VM, you must have much more resources like CPU, hard disk and memory. Besides, you need an image of the operating system (usually in iso file) and install it in the VM environment. This will take a lot of resources and time. With kubernetes, you can solve these problems. Kubernetes provides much more things of course but in the scope of this article, we just discuss how it applies in SAFplus deployment. Let’s discover it now.

Overview

Kubernetes, often abbreviated as K8s, is an open-source platform designed to automate the deployment, scaling, and management of containerized applications. It acts as an orchestration system for containers, enabling developers and operations teams to efficiently manage large-scale, distributed applications.

Some core concepts

Containers

  • Similar to VMs, but they have relaxed isolation properties to share the Operating System (OS) among the applications. Therefore, containers are considered lightweight
  • Has its own filesystem, share of CPU, memory, process space, and more. As they are decoupled from the underlying infrastructure, they are portable across clouds and OS distributions.
  • If 2 or more containers are inside a pod, they share the same IP address. And they can be identified by the port. In contrast, if one container is inside a pod, they have the different IP addresses, because of this, it’s recommended that SAFplus-based applications deployments should be in “one container in one pod”, which means, an app image should be deployed in a container which is inside a pod.

Pods

  • A Pod is the smallest deployable unit in Kubernetes.
  • It represents one or more containers that are tightly coupled and run together on the same node.
  • Containers inside the same Pod share:
    • The same network namespace (→ same IP address, can talk to each other over localhost).
    • Optionally the same storage volumes.

In analogy, a container is like a single program running in its own box. And a Pod is like a shipping container that can carry one or more boxes that belong together, and Kubernetes moves that container around.

In brief, a Pod is the smallest unit of work in Kubernetes, and it groups together one or more containers that should run together, share the same IP, and possibly storage.

How to deploy and run SAFplus-base applications

System requirements

  • For testing / learning: 2+ cores CPU, 2+ GB RAM, 20+ GB disk (single node)
  • In production: 4+ cores CPU, 8 GB+ RAM, SSD storage, multiple nodes.
  • OS: any Linux distributions like Ubuntu 22.04 or newer, Debian 11 or newer, RedHat, CentOS, Fedora…

Installation

  • Minikube: is a tool that lets you run Kubernetes locally. Refer to: https://minikube.sigs.k8s.io/docs/start/?arch=%2Flinux%2Fx86-64%2Fstable%2Fbinary+download
  • Docker or podman (plays as a driver for minikube). Refer to: https://docs.docker.com/engine/install/
  • kubectl: is the Kubernetes command-line tool, allowing you to run commands against Kubernetes clusters. You can use kubectl to deploy applications, inspect and manage cluster resources, and view logs. Refer to: https://kubernetes.io/docs/tasks/tools/install-kubectl-linux

 

Steps to deploy and run applications:

  • Create the dockerfiles: specify the OS, images to deploy to the container and what to do with this image…
  • Create the Yalm files: define the pods and containers properties like pod/container name, image, command and arguments… If you have 2 images (2 nodes), there are 2 definitions for 2 containers (one node will be run on one container)
  • Build the images using docker or podman
  • Using minikube to load the images
  • Using kubectl to get the containers to run

Note that, UDP transport must be enabled with cloud mode

Examples: deploy 2 images running on 2 containers, one container inside one pod

Dockerfiles:

Dockerfile-node0:

FROM ubuntu:22.04

WORKDIR /app

RUN rm -rf ./*

RUN apt update && apt install -y python3 && rm -rf /var/lib/apt/lists/*

COPY Node0I0.tgz ./

RUN tar xzf Node0I0.tgz && rm Node0I0.tgz

 

Dockerfile-node1:

FROM ubuntu:22.04

WORKDIR /app

RUN rm -rf ./*

RUN apt update && apt install -y python3 && rm -rf /var/lib/apt/lists/*

COPY Node0I1.tgz ./

RUN tar xzf Node0I1.tgz && rm Node0I1.tgz

 

Yalm file: safplus-pods.yaml

apiVersion: v1

kind: Pod

metadata:

  name: safplus-node0-pod

spec:

  containers:

  – name: node0

    image: node0:latest

    imagePullPolicy: IfNotPresent # Add this line

    command: [“/bin/bash”, “-c”]     

    args: [“/app/etc/init.d/safplus start ; sleep infinity”]

apiVersion: v1

kind: Pod

metadata:

  name: safplus-node1-pod

spec:

  containers:

  – name: node1

    image: node1:latest

    imagePullPolicy: IfNotPresent # Add this line

    command: [“/bin/bash”, “-c”]

    args: [“/app/etc/init.d/safplus start; sleep infinity”]

 

Build images: 

docker build –no-cache -f Dockerfile-node0 -t node0:latest .

docker build –no-cache -f Dockerfile-node1 -t node1:latest .

Load images:

minikube image load node0:latest

minikube image load node1:latest

Start the containers:

kubectl apply -f safplus-pods.yaml

After this step, two nodes will run on the respective containers with one active and one standby

Conclusion

Kubernetes is a good environment to deploy and run SAFplus-based applications with the purpose of testing or even actual running. It has more advantages than the VM: no installations, no more resources… You can discover more features it provides to adapt to your needs.

Other supports, please send emails to support@openclovis.org