|
2 | 2 | sidebar_position: 5 |
3 | 3 | --- |
4 | 4 |
|
5 | | -# Plain |
| 5 | +# Containers deployment |
| 6 | +## Minimal deployment |
| 7 | +To deploy container with minimal configuration, definition below is enough: |
| 8 | +```cgo |
| 9 | +prefix: simplecontainer.io/v1 |
| 10 | +kind: containers |
| 11 | +meta: |
| 12 | + group: example |
| 13 | + name: busybox |
| 14 | +spec: |
| 15 | + image: busybox |
| 16 | + tag: latest |
| 17 | + replicas: 1 |
| 18 | + entrypoint: ["sleep"] |
| 19 | + args: ["3600"] |
| 20 | +``` |
| 21 | +Entrypoint and args are additional configuration so that container keeps alive. |
| 22 | + |
| 23 | +```bash |
| 24 | +smrctl apply https://raw.githubusercontent.com/simplecontainer/examples/refs/heads/main/tests/minimal/definitions/Containers.yaml |
| 25 | +``` |
| 26 | +This deploys busybox container. |
| 27 | + |
| 28 | +## Readiness and dependency |
| 29 | + |
| 30 | +Database is often used as the dependency for other services. This can easily be achieved. |
| 31 | + |
| 32 | +```cgo |
| 33 | +kind: containers |
| 34 | +prefix: simplecontainer.io/v1 |
| 35 | +meta: |
| 36 | + name: mysql |
| 37 | + group: mysql |
| 38 | +spec: |
| 39 | + image: "mysql" |
| 40 | + tag: "8.0" |
| 41 | + replicas: 1 |
| 42 | + spread: |
| 43 | + spread: uniform |
| 44 | + envs: |
| 45 | + - MYSQL_ROOT_PASSWORD=(( .password )) |
| 46 | + - CONTAINER_NAME=(( .testing )) |
| 47 | + ports: |
| 48 | + - container: "3306" |
| 49 | + volumes: |
| 50 | + - type: bind |
| 51 | + hostPath: /tmp |
| 52 | + mountPoint: /tmp |
| 53 | + configurations: |
| 54 | + - group: mysql |
| 55 | + name: config |
| 56 | + resources: |
| 57 | + - group: mysql |
| 58 | + name: config |
| 59 | + key: my.cnf |
| 60 | + mountPoint: /etc/my.cnf |
| 61 | + - group: mysql |
| 62 | + name: config |
| 63 | + key: secret.config.file |
| 64 | + mountPoint: /etc/secret.cnf |
| 65 | + readiness: |
| 66 | + - name: "mysql" |
| 67 | + timeout: "60s" |
| 68 | + command: ["mysqladmin", "ping", "-h", "localhost", "-p(( .password ))"] |
| 69 | + configuration: |
| 70 | + username: "root" |
| 71 | + password: (( lookup "secret/mysql/password:password" | base64decode )) |
| 72 | + testing: (( lookup "runtime/container/configuration:name" )) |
| 73 | + testing2: (( lookup "runtime/container/configuration:name" )) |
| 74 | + secret: "secret" |
| 75 | +``` |
| 76 | + |
| 77 | +To create another container that depends on the database, definition: |
| 78 | + |
| 79 | +```cgo |
| 80 | +kind: containers |
| 81 | +prefix: simplecontainer.io/v1 |
| 82 | +meta: |
| 83 | + name: nginx |
| 84 | + group: nginx |
| 85 | + labels: |
| 86 | + test: testing2345 |
| 87 | +spec: |
| 88 | + image: "nginx" |
| 89 | + tag: "1.23.3" |
| 90 | + replicas: 2 |
| 91 | + dependencies: |
| 92 | + - prefix: "simplecontainer.io/v1" |
| 93 | + group: "mysql" |
| 94 | + name: "*" |
| 95 | + timeout: "30s" |
| 96 | + ports: |
| 97 | + - container: "80" |
| 98 | + - container: "443" |
| 99 | + resources: |
| 100 | + - group: nginx |
| 101 | + name: config |
| 102 | + key: nginx-configuration |
| 103 | + mountPoint: /etc/nginx/conf.d/default.conf |
| 104 | + configuration: |
| 105 | + username: "root" |
| 106 | +``` |
| 107 | + |
| 108 | +Dependencies relies on the group and name to match. Container/s that is/are referenced in the dependency needs to have it's |
| 109 | +own readiness completed successfully so that container will mark dependency as ready. |
| 110 | + |
| 111 | +By default, as soon as the container is running readiness is successful. |
| 112 | + |
| 113 | +Since container can have more replicas the wildcard `*` can be used in the name to wait for all container replicas. |
| 114 | + |
| 115 | +Otherwise, it can be configured to match only specific instance using generated name eg. `mysql-mysql-1`. This follows naming convention. |
0 commit comments