Skip to content

Commit e8f31b5

Browse files
authored
Merge pull request #172 from BCDevOps/pod-life-cycle-updates
Improve pod lifecycle instructions
2 parents 52d760e + 66ced73 commit e8f31b5

10 files changed

+69
-21
lines changed

101-lab/content/15_pod_lifecycle.md

Lines changed: 69 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,68 @@ A Pod can be extended beyond the normal operation of the container by allowing d
55
- modify the default `entrypoint` of a container
66

77
## 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+
810
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.
911

1012
__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+
![](./images/15_pod_lifecycle_03.png)
18+
19+
- Using the left navigation menu, select 'Integrations' and choose the 'New Integration'
20+
21+
![](./images/15_pod_lifecycle_04.png)
22+
23+
- Next, select the option to create an 'Incoming WebHook'
24+
25+
![](./images/15_pod_lifecycle_05.png)
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+
![](./images/15_pod_lifecycle_06.png)
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+
![](./images/15_pod_lifecycle_07.png)
34+
35+
- Next the OpenShift Web Console, navigate to `Topology` and select your `rocketchat-[username]` deployment.
1236
- Navigate to the __YAML__ tab.
1337
> If you wish to perform this from the cli with the `oc` tool, type `oc edit deployment/rocketchat-[username]`
1438
1539

1640
![](./images/12_pod_lifecycle_01.png)
1741

18-
- Add the following section of code under `spec: -> template: -> spec:`
19-
20-
```
21-
initContainers:
22-
- name: init
23-
image: giantswarm/tiny-tools
24-
command: ["/bin/sh", "-c", "c=$(curl -X POST -H 'Content-Type: application/json' --data '{\"text\":\"Say Hello\"}' https://chat.pathfinder.gov.bc.ca/hooks/xxx/xxx)"]
42+
- 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
2559
```
2660
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+
![](./images/15_pod_lifecycle_08.png)
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+
![](./images/15_pod_lifecycle_09.png)
69+
2970
- Explore the `Pod Details` to notice the difference with the Init Container
3071

3172
![](./images/12_pod_lifecycle_02.png)
@@ -37,34 +78,41 @@ oc -n [-dev] logs rocketchat-[username]-[pod-id] -c init
3778
```
3879

3980
## Lifecycle Hooks
40-
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.
4182

4283
- From the Web Console, navigate to the `rocketchat-[username]` deployment and click on `YAML` tab
4384
- 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:
4788
postStart:
4889
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)"]
5091
preStop:
5192
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)"]
5394
```
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:
5696

97+
![](./images/15_pod_lifecycle_10.png)
5798

5899
## Overriding the Entrypoint
59100
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.
60101

61102
- From the Web Console, navigate to the `rocketchat-[username]` deployment and click on `YAML` tab
62103
- 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`
64105

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)"]
65108
```
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+
![](./images/15_pod_lifecycle_11.png)
113+
114+
115+
Be sure to save the changes to your YAML. Then:
68116
- Take note of the pattern that will happen in the rocketchat notification screen
69117
- Remove the previous command to enable the rocketchat instance to start properly again
70118

473 KB
Loading
346 KB
Loading
710 KB
Loading
644 KB
Loading
166 KB
Loading
1.07 MB
Loading
119 KB
Loading
444 KB
Loading
1.06 MB
Loading

0 commit comments

Comments
 (0)