-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathstart.sh
executable file
·285 lines (243 loc) · 6.85 KB
/
start.sh
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
#!/usr/bin/env sh
# Author: Scott McCarty <[email protected]>
# Twitter: @fatherlinux
# Date: 10/16/2019
# Description: Demonstrate the process of finding, running, building, sharing, and deploying containers with freely
# distributable tools like Podman and Red Hat Universal Base Image.
# Setting up some colors for helping read the demo output.
# Comment out any of the below to turn off that color.
bold=$(tput bold)
cyan=$(tput setaf 6)
reset=$(tput sgr0)
read_color() {
read -p "${bold}$1${reset}"
}
echo_color() {
echo "${cyan}$1${reset}"
}
setup() {
echo_color "Setting up"
}
intro() {
read -p "Finding, running, building, sharing, and deploying containers with freely distributable tools like Podman and Red Hat Universal Base Image"
echo
}
find_containers() {
echo
echo_color "A good artist is a good thief, so let's see if we can find a good container base image"
echo
read_color "podman search registry.access.redhat.com/ubi8"
podman search registry.access.redhat.com/ubi8
echo
echo_color "So, podman found these, but how do we know they are any good?"
echo
read_color "Go look at http://access.redhat.com/containers"
}
run_containers() {
echo
echo_color "OK, so we trust these container images. Let's run one"
echo
read_color "podman run -it ubi8 bash"
podman run -it ubi8 bash
}
build_containers() {
echo
echo_color "Trusted base images are great, but you can't do much with a base image. You need to add value"
echo_color "So, let's install some packages"
echo
read_color "podman build -t quay.io/fatherlinux/ubi8-sharing -f Dockerfile"
podman build -t quay.io/fatherlinux/ubi8-sharing -f Dockerfile
echo
echo_color "Let's verify that the image is built and saved locally"
echo
read_color "podman images"
podman images
}
share_containers() {
echo
echo_color "Now, let's push the image out to quay.io"
echo
read_color "podman push quay.io/fatherlinux/ubi8-sharing"
podman push quay.io/fatherlinux/ubi8-sharing
}
deploy_containers() {
# Simple Use Case
echo
read_color "Once we have shared some container images, how do we deploy them in production?"
read_color "There are often scalibility, and high availability requirements right?"
read_color "We need to get to an enterpise Kubernetes platform like OpenShift"
read_color "But, how do we get from Podman to Kubernetes?"
read_color "Easy, with a feature called 'podman generate kube'"
echo
echo_color "First, lets run a container with podman"
echo
read_color "podman run -id quay.io/fatherlinux/ubi8-sharing bash"
podman run --name tron -id quay.io/fatherlinux/ubi8-sharing bash
echo
echo_color "Verify that the new container is running"
echo
read_color "podman ps"
podman ps
echo
echo_color "Now, generate some Kubernetes yaml from the running container"
echo
read_color "podman generate kube tron > tron.yaml"
podman generate kube tron > tron.yaml
echo
echo_color "Inspect the yaml created. This can be used by Kubernetes"
echo
read_color "vim tron.yaml"
vim tron.yaml
echo
echo_color "Let's use CodeReady Containers"
echo_color "It provides an all in one OpenShift environment"
echo_color "CRC lets us simulate a production Kubernetes installation"
echo
read_color "oc get nodes"
oc get nodes
echo
read_color "oc get projects"
oc get projects
echo
echo_color "To use the consume that application YAML that we created with Podman, let's create a new project"
echo
read_color "oc new-project tron"
oc new-project tron
echo
echo_color "Ensure the project was created"
echo
read_color "oc get projects"
oc get projects
echo
echo_color "Use the pod definition created by podman with Kubernetes"
echo
read_color "oc create -f tron.yaml"
oc create -f tron.yaml
echo
echo_color "Now, verify that it's being created"
echo
read_color "oc get pods -w"
oc get pods -w
echo
read_color "oc describe pod tron"
oc describe pod tron
echo
read_color "oc get pods"
oc get pods
echo
read_color "Now, let's try a more advanced use case"
# Advanced Use Case
echo
echo_color "Let's use podman to create a pod"
echo_color "A Recognizer is a large, hovering vehicle with a central cockpit"
echo_color "They are used to hunt down free programs on the grid!"
echo
read_color "podman pod create --publish 8080:80 -n recognizer"
podman pod create --publish 8080:80 -n recognizer
echo
echo_color "Now, let's add Flynn to the Recognizer so that he can track down the stolen video game code"
echo
read_color "podman run -id --pod recognizer --name flynn ubi8"
podman run -id --pod recognizer --name flynn ubi8
echo
echo_color "Now, let's add Bit to the Recognizer so that he's not alone"
echo
read_color "podman run -id --pod recognizer --name bit ubi8"
podman run -id --pod recognizer --name bit ubi8
echo
echo_color "Now let's make sure the recognizer exists"
echo
read_color "podman pod list --ns --ctr-names"
podman pod list --ns --ctr-names
echo
echo_color "Make sure Flynna and Bit are in the Recognizer pod"
echo
read_color "podman pod inspect recognizer"
podman pod inspect recognizer
echo
read_color "podman ps"
podman ps
echo
echo_color "Generate kubernetes yaml"
echo
read_color "podman generate kube -s recognizer > recognizer.yaml"
podman generate kube -s recognizer > recognizer.yaml
echo
echo_color "Inspect the yaml created. Notice that it's more advanced."
echo
read_color "vim recognizer.yaml"
vim recognizer.yaml
echo
echo_color "Create a new OpenShift project in CRC"
echo
read_color "oc new-project tron-legacy"
oc new-project tron-legacy
echo
read_color "oc get projects"
oc get projects
echo
echo_color "Use the pod definition created by podman with Kubernetes"
echo
read_color "oc create -f recognizer.yaml"
oc create -f recognizer.yaml
echo
echo_color "Now, verify that it's being created"
echo
read_color "oc get pods -w"
oc get pods -w
echo
read_color "oc describe pod recognizer"
oc describe pod recognizer
echo
read_color "oc get pods"
oc get pods
echo
read_color "oc get svc"
oc get svc
echo
echo_color "Bonus: what if I want to run a container with systemd?"
echo
echo_color "Lets use our simple tron example"
echo
read_color "podman generate systemd tron"
podman generate systemd tron
}
pause() {
echo
read -p "Enter to continue"
clear
}
clean_images_and_containers() {
echo
read_color "Now, let's clean up the containers and pods"
echo
read_color "podman kill -a"
podman kill -a
echo
read_color "podman rm -a"
podman rm -a
echo
read_color "podman pod kill -a"
podman pod kill -a
echo
read_color "podman pod rm -a"
podman pod rm -a
echo
read_color "oc delete project tron"
oc delete project tron
echo
read_color "oc delete project tron-legacy"
oc delete project tron-legacy
}
setup
intro
find_containers
run_containers
build_containers
share_containers
deploy_containers
clean_images_and_containers
echo
read -p "End of Demo!!!"
echo
echo "Thank you!"