-
Notifications
You must be signed in to change notification settings - Fork 0
/
webapp1-deployment.yaml
84 lines (83 loc) · 2.86 KB
/
webapp1-deployment.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
apiVersion: apps/v1
kind: Deployment
metadata:
name: webapp-1
# Just some extra metadata in the form of annotations
annotations:
description: Deployment for simple web app (type 1)
spec:
replicas: 2
selector:
matchLabels:
app: webapp-1
template:
metadata:
labels:
app: webapp-1
spec:
# Pod attributes
nodeSelector:
# These pods replicas will be running on nodes tagged with a specific hardware requirement
hardwareReq: type1
affinity:
podAntiAffinity:
# Pod anti affinity to separate pods of webapp 1 among them in different nodes
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app
operator: In
values:
- webapp-1
topologyKey: kubernetes.io/hostname
# Container attributes
containers:
- name: webserver
image: nginx:1.7.9
env:
# The common parts for messages in apps are taken from configMaps
- name: GREETING_TEXT
valueFrom:
configMapKeyRef:
name: webapp-vars
key: GREETING_TEXT
- name: OUTPUT_TEXT
valueFrom:
configMapKeyRef:
name: webapp-vars
key: OUTPUT_TEXT
# Use of the Downward API to retrieve pod and node names
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
lifecycle:
postStart:
# For demo purposes, we execute these commands just after container start to customize the server message for app1 based on an env variable.
# In addition, nginx port is changed to 3000
# Some logging info is written
exec:
command:
- "/bin/bash"
- "-c"
- >
`# Customizing web page content for webapp 1 and changing serving port from 80 to 3000`
echo ${GREETING_TEXT} TYPE 1 > /usr/share/nginx/html/index.html;
sed -i 's/ 80;/ 3000;/g' /etc/nginx/conf.d/default.conf;
nginx -s reload;
`# Logging start on a file in folder`
echo ${POD_NAME} ${OUTPUT_TEXT} TYPE 1 STARTED on node ${NODE_NAME} > /app-logs/postStart
ports:
# As nginx port has been changed from 80 to 3000 in nginx, the container now listens through it
- containerPort: 3000
volumeMounts:
- name: output-volume
mountPath: /app-logs
volumes:
- name: output-volume
# Node volume where containers log their lifecycle activity
emptyDir: {}