-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkubedeploy.yaml
More file actions
139 lines (134 loc) · 4.25 KB
/
Copy pathkubedeploy.yaml
File metadata and controls
139 lines (134 loc) · 4.25 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# Complete set of Kubernetes definitions for the Boot application and key/value store.
# Service definition for Redis. This is only exposed inside the cluster.
apiVersion: v1
kind: Service
metadata:
name: keyvalue-srv
labels:
application: kubeboot
spec:
selector:
# group all services under application label, component selects individual services
application: kubeboot
component: redis
# Redis is only used from within the cluster, no NodePort is needed
type: ClusterIP
ports:
- port: 6379
protocol: TCP
targetPort: 6379
---
# Deployment definition for the Redis pods. This stores data in a persistent volume, since it is
# not stateless it is defined as a StatefulSet.
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: keyvalue
spec:
# our Redis setup is not highly available and only has a single master
replicas: 1
selector:
matchLabels:
# application and component labels match service above.
application: kubeboot
component: redis
serviceName: keyvalue-srv
template:
metadata:
labels:
# both application and component labels are used for the match
application: kubeboot
component: redis
spec:
containers:
- name: redis
# use the official Redis image (smaller Alpine edition)
image: redis:4-alpine
# configure persistence (the Redis default config has persistence disabled by default)
args: ["--appendonly", "yes", "--save", "900", "1", "--save", "30", "2"]
ports:
- containerPort: 6379
volumeMounts:
# mount our persistent volume (defined below as volumeClaimTemplate)
- name: data
# the official Redis image uses /data by default
mountPath: /data
# every pod will get a PersistentVolume as per the following template.
# note the storageclassname, this can be omitted to get the default storage class for the cluster.
volumeClaimTemplates:
- metadata:
name: data
spec:
accessModes:
- ReadWriteOnce
storageClassName: standard
resources:
requests:
# 1GiB storage is more than enough for our example
storage: 1Gi
---
# Service definition for the Spring Boot application. This will be exposed outside.
apiVersion: v1
kind: Service
metadata:
name: kubebootsvc
labels:
application: kubeboot
spec:
selector:
# the application label is the same; the component label will select the pods which are running the Boot app.
application: kubeboot
component: frontend
# use LoadBalancer to expose service. In Docker for OSX this will expose the service on localhost
# port 80; on Minikube you have to retrieve the IP or define an ingress.
type: LoadBalancer
ports:
- port: 80
protocol: TCP
targetPort: 8080
---
# Deployment definition for the Spring Boot pods. Since the app is stateless use Deployment instead
# of StatefulSet.
apiVersion: apps/v1
kind: Deployment
metadata:
name: kubeboot
spec:
# run two replicas for high availability
replicas: 2
selector:
matchLabels:
# indicate same application, but frontend component
application: kubeboot
component: frontend
template:
metadata:
labels:
# our app has both Connexion and Redis pods, make sure we separate them by label
application: kubeboot
component: frontend
spec:
containers:
- name: kubeboot
# Docker image to be build with Minikube's Docker daemon (minikube docker-env)
# see README.md on how to build, and never try to pull the image
image: kubeboot:minikube
imagePullPolicy: Never
env:
# overrides spring.redis.host inside application.properties
# points to the name of the Redis service
- name: SPRING_REDIS_HOST
value: "keyvalue-srv"
# make Pod IP visible in the environment var to be picked up by Boot
- name: MY_POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
ports:
- containerPort: 8080
# use Boot Actuator for readiness probe. This implies a Pod will not be ready
# until it has successfully connected to Redis.
readinessProbe:
httpGet:
path: /actuator/health
port: 8080