Deploying containers using applying definitions approach

There are two ways to deploy containers on the simplecontainer node:

  • Applying definitions using smr tool
  • GitOps approach

Gitops approach

For the GitOps approach focus on the next reading.

Deploy containers using GitOps approach
Simplecontainer enables the GitOps approach to deploying containers on single or multiple simplecontainer hosts. This allows the simplecontainer to pull the latest changes on the definitions from the git repository instead of pushing the changes to the simplecontainer via CLI. First, you need to have simplecontainer running and CLI configured

Applying definitions

Create secret

A secret is a type of object that can hold sensitive data that can be fed into containers via templating.

To create a secret:

smr secret create secret.mysql.mysql.password 123456789

This will create a secret object on the simplecontainer node and store it in an encrypted key-value store. This secret can be referenced for injecting sensitive data into containers.

Create configuration

Configuration is a type of object that can hold key-value pairs. The value part of the key value also can inject secrets that are already in the store.

smr apply https://raw.githubusercontent.com/simplecontainer/examples/main/tests/simple-dependency-readiness/mysql-config.yaml
kind: configuration
meta:
  group: mysql
  name: "*"
spec:
  data:
    password: "{{ secret.mysql.mysql.password }}"

This configuration definition holds the password which will be replaced with a secret at the container runtime.

Create resource

The resource is a type of object that holds larger configurations or files that are intended to be mounted into the container as a file.

smr apply https://raw.githubusercontent.com/simplecontainer/examples/main/tests/simple-dependency-readiness/mysql-config.yaml
kind: resource
meta:
  group: mysql
  name: "config"
spec:
  data:
    my.cnf: |
      [mysqld]
      bind-address=0.0.0.0

To create additional resources for this example run:

smr apply https://raw.githubusercontent.com/simplecontainer/examples/main/tests/simple-dependency-readiness/nginx-config.yaml
smr apply https://raw.githubusercontent.com/simplecontainer/examples/main/tests/simple-dependency-readiness/traefik-config.yaml

Create containers

The containers object is used for the definition of a bundle of containers that are logically connected to each other. Otherwise, container object can be used for a single container.

smr apply https://raw.githubusercontent.com/simplecontainer/examples/main/tests/simple-dependency-readiness/containers.yaml
kind: containers
meta:
  name: logical-group
  group: test
spec:
  mysql:
    meta:
      name: mysql
      group: mysql
    spec:
      container:
        image: "mysql"
        tag: "8.0"
        replicas: 2
        envs:
          - "MYSQL_ROOT_PASSWORD={{ configuration.password }}"
        ports:
          - container: "3306"
        resources:
          - group: mysql
            name: config
            key: my.cnf
            mountPoint: /etc/my.cnf
        readiness:
          - name: "mysql"
            timeout: "60s"
            command: ["mysqladmin", "ping", "-h", "localhost", "-p{{ configuration.password }}"]
        configuration:
          username: "root"
          password: "{{ secret.mysql.mysql.password }}"
  traefik:
    meta:
      name: traefik
      group: traefik
    spec:
      options:
        enabled: false
      container:
        image: "traefik"
        tag: "v2.5"
        replicas: 1
        volumes:
          - type: "bind"
            hostPath: "/var/run/docker.sock"
            mountPoint: "/var/run/docker.sock"
        dependencies:
          - group: "mysql"
            name: "*"
            timeout: "30s"
        ports:
          - container: "80"
            host: "80"
          - container: "443"
            host: "443"
          - container: "8080"
            host: "8888"
        resources:
          - group: traefik
            name: config
            key: traefik-configuration
            mountPoint: /etc/traefik/traefik.yml
  nginx:
    meta:
      name: nginx
      group: nginx
    spec:
      options:
        enabled: false
      container:
        image: "nginx"
        tag: "1.23.3"
        replicas: 1
        dependencies:
          - group: "mysql"
            name: "*"
            timeout: "30s"
        ports:
          - container: "80"
          - container: "443"
        resources:
          - group: nginx
            name: config
            key: nginx-configuration
            mountPoint: /etc/nginx/conf.d/default.conf
        configuration:
          username: "root"

After applying containers definition the containers will start in order defined be it on one node or spread around the cluster.