Skip to content
This repository was archived by the owner on Mar 23, 2019. It is now read-only.

Commit ccbb328

Browse files
marc-sensenichChris Houseknecht
authored and
Chris Houseknecht
committed
Add proposal for Multiple Containers per Pod (#639)
* Add proposal for Multiple Containers per Pod * Remove unnecessary wording * Added Examples to Proposal Added example cases and generated output to the proposal outlining how this would be managed with Docker and Kubernetes
1 parent 85430f9 commit ccbb328

File tree

1 file changed

+165
-0
lines changed

1 file changed

+165
-0
lines changed

proposals/multiple-containers.md

+165
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
# Supporting Multiple Containers Per Service in Kubernetes and OpenShift
2+
3+
## Table of Contents
4+
- [Reasoning](#Reasoning)
5+
- [Declaring Multiple Containers Per Service](#declaring-multiple-containers-per-service)
6+
- [Declarations and Generated Templates](#declarations-and-generated-templates)
7+
8+
## Reasoning
9+
10+
Some services are composed of multiple containers that are coupled and share resources to form a single cohesive service. Common cases of this are sidecar and ambassador containers. Within Ansible Container currently it is a single container per service, which allows for the generation of the images used within these services. However these images are built separately and deployed to a server. However, the container.yml file is not able to act as a single source-controlled piece of code to define the state of the deployable application.
11+
12+
## Declaring Multiple Containers Per Service
13+
14+
To achieve this the service section will accept a new property, containers, which will allow for the declaration of 1-N containers per service. The addition of this property will allow for the maintenance of existing applications by using an check when building and deploying the service; e.g. `if 'containers' in service`.
15+
16+
### Multiple Containers Declaration Example
17+
18+
```yaml
19+
services:
20+
web:
21+
containers:
22+
- from: centos:7
23+
entrypoint: [/usr/bin/entrypoint.sh]
24+
working_dir: /
25+
user: apache
26+
command: [/usr/bin/dumb-init, httpd, -DFOREGROUND]
27+
ports:
28+
- 8000:8080
29+
- 4443:8443
30+
roles:
31+
- apache-container
32+
volumes:
33+
- static-content:/var/www/static
34+
container_name: apache
35+
- from: centos:7
36+
command: [/usr/bin/dumb-init, file-refresher, --out-dir, /var/www/static]
37+
entrypoint: [/usr/bin/entrypoint.sh]
38+
user: refresher
39+
roles:
40+
- apache-file-refresher
41+
volumes:
42+
- static-content:/var/www/static
43+
container_name: apache-file-refresher
44+
volumes:
45+
static-content:
46+
docker: {}
47+
k8s:
48+
force: false
49+
state: present
50+
access_modes:
51+
- ReadWriteOnce
52+
requested_storage: 1Gi
53+
metadata:
54+
annotations: 'volume.beta.kubernetes.io/mount-options: "discard"'
55+
```
56+
57+
## Declarations and Generated Templates
58+
59+
In order to maintain backwards compatibility, declaring a service with a single container will remain the same, a single object representing the service.
60+
61+
### Docker
62+
63+
#### Case Management
64+
65+
Given that Docker may only have one container per service, in the case that the `containers` directive is encountered the following cases could occur:
66+
67+
- Containers is a list of container declarations
68+
- In the case that there is a list of container declarations and the engine for deployment is Docker, Ansible Container would create each container as a seperate service using the following naming convention for the service: `{service-name}-{container-name}`
69+
70+
**Example Template**
71+
```yaml
72+
services:
73+
web-apache:
74+
entrypoint:
75+
- /usr/bin/entrypoint.sh
76+
working_dir: /
77+
user: apache
78+
command:
79+
- /usr/bin/dumb-init
80+
- httpd
81+
- -DFOREGROUND
82+
image: apache:latest
83+
exposes:
84+
- 8000
85+
- 4443
86+
volumes:
87+
- static-content:/var/www/static
88+
web-apache-file-refresher:
89+
command:
90+
- /usr/bin/dumb-init
91+
- file-refresher
92+
- --out-dir
93+
- /var/www/static
94+
entrypoint:
95+
- /usr/bin/entrypoint.sh
96+
user: refresher
97+
image: apache-file-refresher:latest
98+
volumes:
99+
- static-content:/var/www/static
100+
```
101+
- Containers is a container declaration object
102+
- In the case that there is a single container object under the `containers` declaration. The service deployment would execute as it does currently.
103+
- Containers is not declared, in place is the standard container declaration
104+
- If containers is not declared, but a container declaration is under the service, the execution would continue as normally
105+
106+
### Kubernetes
107+
108+
#### Case Management
109+
110+
- Containers is a list of container declarations
111+
- In the case that there is a list of container declarations, then the service would be generated with a list of containers in it's spec
112+
- Containers is a container declaration object
113+
- In the case that there is a single container object under the `containers` declaration. The service deployment would execute as it does currently.
114+
- Containers is not declared, in place is the standard container declaration
115+
- If containers is not declared, but a container declaration is under the service, the execution would continue as normally
116+
117+
Using the services declaration presented in [Multiple Containers Declaration Example](#multiple-containers-declaration-example) the following would be generated for deploying the service to Kubernetes.
118+
119+
#### Generated Template
120+
121+
```yaml
122+
k8s_v1beta1_deployment:
123+
state: present
124+
force: false
125+
resource_definition:
126+
apiVersion: extensions/v1beta1
127+
kind: deployment
128+
metadata:
129+
name: apache
130+
labels:
131+
app: web
132+
service: apache
133+
namespace: web
134+
spec:
135+
template:
136+
metadata:
137+
labels:
138+
app: web
139+
service: apache
140+
spec:
141+
containers:
142+
- name: apache
143+
securityContext: {}
144+
state: present
145+
volumeMounts:
146+
- readOnly: false
147+
mountPath: /var/www/static
148+
name: static-content
149+
image: apache:latest
150+
- name: apache-file-refresher
151+
securityContext: {}
152+
state: present
153+
volumeMounts:
154+
- readOnly: false
155+
mountPath: /var/www/static
156+
name: static-content
157+
image: apache-file-refresher:latest
158+
volumes:
159+
- name: static-content
160+
persistentVolumeClaim:
161+
claimName: static-content
162+
replicas: 1
163+
strategy:
164+
type: RollingUpdate
165+
```

0 commit comments

Comments
 (0)