You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 101-lab/content/15_pod_lifecycle.md
+69-21Lines changed: 69 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,27 +5,68 @@ A Pod can be extended beyond the normal operation of the container by allowing d
5
5
- modify the default `entrypoint` of a container
6
6
7
7
## Init Containers
8
+
Init containers are specialized containers that run before app containers in a pod. Init containers can contain utilities or setup scripts not present in an app image.
9
+
8
10
Init containers are best used to prepare the pod for normal operation. In this lab, you will add a simple init container that posts a message to rocketchat with your pod hostname.
9
11
10
12
__Objective__: Create an init container
11
-
- From the Web Console, navigate to `Topology` and select your `rocketchat-[username]` deployment.
13
+
- Open your Rocketchat web application from its web route, ensuring to log in as the admin user that your previously created.
14
+
15
+
- Click on the three-dot icon to see more menu options, and choose 'Administration'
16
+
17
+

18
+
19
+
- Using the left navigation menu, select 'Integrations' and choose the 'New Integration'
20
+
21
+

22
+
23
+
- Next, select the option to create an 'Incoming WebHook'
24
+
25
+

26
+
27
+
- Configure the WebHook. Be sure to set 'enabled' to 'true', choose the account name you set earlier, choose the default #general channel. Optionally, you can link to an avatar image or set and emoji as the avatar. Be sure to save the settings at the bottom right of the page, and confirm that no errors appear at the top right of the page.
28
+
29
+

30
+
31
+
- Once these settings are saved, navigate to the 'Integrations' page again and take note of the webhook URL that is generated.
32
+
33
+

34
+
35
+
- Next the OpenShift Web Console, navigate to `Topology` and select your `rocketchat-[username]` deployment.
12
36
- Navigate to the __YAML__ tab.
13
37
> If you wish to perform this from the cli with the `oc` tool, type `oc edit deployment/rocketchat-[username]`
14
38
15
39
16
40

17
41
18
-
- Add the following section of code under `spec: -> template: -> spec:`
- After replacing the URL below with the webhook URL from the previous step, add the following section of code under `spec: -> template: -> spec:`. As always with YAML, pay close attention to the formatting and indenting.
43
+
44
+
```YAML
45
+
initContainers:
46
+
- name: init
47
+
image: giantswarm/tiny-tools
48
+
command:
49
+
- /bin/sh
50
+
- '-c'
51
+
- >-
52
+
c=$(curl -X POST -H 'Content-Type: application/json' --data
53
+
'{"text":"Say Hello"}'
54
+
http://[YOUR_WEBHOOK_URL])
55
+
resources: {}
56
+
terminationMessagePath: /dev/termination-log
57
+
terminationMessagePolicy: File
58
+
imagePullPolicy: Always
25
59
```
26
60
27
-
- Select Save
28
-
- Ask the instructor to ensure the rocketchat instance is displayed to the class
61
+
- Save your changes to the YAML. It should look similar to this:
62
+
63
+

64
+
65
+
66
+
- Now that you've added this init container, every time one of your Rocketchat pods initializes, the 'Say Hello' message will be posted to your #general channel on Rocketchat web application.
67
+
68
+

69
+
29
70
- Explore the `Pod Details` to notice the difference with the Init Container
Lifecycle hooks can be configured to start and stop a container properly. The lifecycle hook is tied directly to each container. Add a similar pre and post hook as the `initContainer` to demonstrate when it executes in your rocketchat deployment.
81
+
Lifecycle hooks can be configured to start and stop a container properly. The lifecycle hook is tied directly to each container. Next we will add a similar pre and post hook as the `initContainer` to demonstrate when it executes in your rocketchat deployment.
41
82
42
83
- From the Web Console, navigate to the `rocketchat-[username]` deployment and click on `YAML` tab
43
84
- If you wish to perform this from the cli with the `oc` tool, type `oc edit deployment/rocketchat-[username]`
44
-
- Add the following section of code under `spec: -> template: -> spec: -> containers`
45
-
```
46
-
lifecycle:
85
+
- After replacing both URLs below with the webhook URL from the earlier step, as well as replacing $HOSTNAME with the Add the following section of code under `spec: -> template: -> spec: -> containers`. Again, pay careful attention to the YAML indentation.
86
+
```YAML
87
+
lifecycle:
47
88
postStart:
48
89
exec:
49
-
command: ["/bin/sh", "-c", "c=$(curl -X POST -H 'Content-Type: application/json' --data '{\"text\": \"'\"$HOSTNAME\"' is at the postStart phase, huzzah! \"}' https://chat.pathfinder.gov.bc.ca/hooks/xxx/xxx)"]
90
+
command: ["/bin/sh", "-c", "c=$(curl -X POST -H 'Content-Type: application/json' --data '{\"text\": \"'\"$HOSTNAME\"' is at the postStart phase, hooray! \"}' http://YOUR_WEBHOOK_URL)"]
50
91
preStop:
51
92
exec:
52
-
command: ["/bin/sh", "-c", "c=$(curl -X POST -H 'Content-Type: application/json' --data '{\"text\": \"'\"$HOSTNAME\"' is just about to STOPPPPPP! \"}' https://chat.pathfinder.gov.bc.ca/hooks/xxx/xxx)"]
93
+
command: ["/bin/sh", "-c", "c=$(curl -X POST -H 'Content-Type: application/json' --data '{\"text\": \"'\"$HOSTNAME\"' is just about to STOPPPPPP! \"}' http://YOUR_WEBHOOK_URL)"]
53
94
```
54
-
- Select Save
55
-
- Ask the instructor to ensure the rocketchat instance is displayed to the class
95
+
- Save your changes to the YAML. It should now look similar to this:
56
96
97
+

57
98
58
99
## Overriding the Entrypoint
59
100
It may be necessary, from time to time, to override the initial command/entrypoint of a container image. Generally this is used for troubleshooting purposes, or to override a vendor provided image.
60
101
61
102
- From the Web Console, navigate to the `rocketchat-[username]` deployment and click on `YAML` tab
62
103
- If you wish to perform this from the cli with the `oc` tool, type `oc edit deployment/rocketchat-[username]`
63
-
-Add the following section of code under `spec: -> template: -> spec: -> containers`
104
+
- After replacing $HOSTNAME and your WebHook URL, add the following section of code under `spec: -> template: -> spec: -> containers: -> resources`
64
105
106
+
```YAML
107
+
command: ["/bin/sh", "-c", "c=$(curl -X POST -H 'Content-Type: application/json' --data '{\"text\": \"'\"$HOSTNAME\"' is AN OVERRIDING COMMAND! \"}' https://chat.pathfinder.gov.bc.ca/hooks/xxx/xxx)"]
65
108
```
66
-
command: ["/bin/sh", "-c", "c=$(curl -X POST -H 'Content-Type: application/json' --data '{\"text\": \"'\"$HOSTNAME\"' is AN OVERRIDING COMMAND! \"}' https://chat.pathfinder.gov.bc.ca/hooks/xxx/xxx)"]
67
-
```
109
+
110
+
Your rocketchat deployment YAML should look similar to this (some sections have been collapsed for easier viewing):
111
+
112
+

113
+
114
+
115
+
Be sure to save the changes to your YAML. Then:
68
116
- Take note of the pattern that will happen in the rocketchat notification screen
69
117
- Remove the previous command to enable the rocketchat instance to start properly again
0 commit comments