|
2 | 2 | ## CodeReady Workspaces setup
|
3 | 3 |
|
4 | 4 | 1. Login to your CodeReadyWorkspace (CRW) Editor. The link to this will be provided by your instructor.
|
5 |
| - |
6 | 5 |
|
7 |
| -<p class="warn"> |
8 |
| -If the workspace has not been set up for you, you can create one from this devfile. On CodeReady Workspaces, "Create Workspace > Custom Workspace". Enter this URL to load the TL500 stack:</br> |
9 |
| -<span style="color:blue;"><a href="https://raw.githubusercontent.com/rht-labs/enablement-framework/main/codereadyworkspaces/tl500-devfile.yaml">https://raw.githubusercontent.com/rht-labs/enablement-framework/main/codereadyworkspaces/tl500-devfile.yaml</a><span> |
10 |
| -</p> |
| 6 | +  |
| 7 | + |
| 8 | + <p class="warn"> |
| 9 | + If the workspace has not been set up for you, you can create one from this devfile. On CodeReady Workspaces, "Create Workspace > Custom Workspace". Enter this URL to load the TL500 stack:</br> |
| 10 | + <span style="color:blue;"><a href="https://raw.githubusercontent.com/rht-labs/enablement-framework/main/codereadyworkspaces/tl500-devfile.yaml">https://raw.githubusercontent.com/rht-labs/enablement-framework/main/codereadyworkspaces/tl500-devfile.yaml</a><span> |
| 11 | + </p> |
11 | 12 |
|
12 | 13 | 2. In your IDE (it may take some time to open ... β°βοΈ), open a new terminal by hitting `Terminal > Open Terminal in Specific Container > stack-tl500` from the menu.
|
13 |
| - |
| 14 | + |
| 15 | +  |
14 | 16 |
|
15 | 17 | 3. Notice the nifty default shell in the stack-tl500 container is `zsh` which rhymes with swish. It also has neat shortcuts and plugins - plus all the cool kids are using it π! We will be setting our environment variables in both `~/.zshrc` and `~/.bashrc` in case you want to switch to `bash`.
|
16 | 18 |
|
17 | 19 | 4. Setup your `TEAM_NAME` name in the environment of the CodeReadyWorkspace by running the command below. We will use the `TEAM_NAME` variable throughout the exercises so having it stored in our session means less changing of this variable throughout the exercises πͺ. **Ensure your `TEAM_NAME` consists of only lower case alphanumeric characters or '-', and must start and end with an alphanumeric character (e.g. 'my-name', or '123-abc.)**
|
18 |
| -```bash |
19 |
| -echo export TEAM_NAME="<TEAM_NAME>" | tee -a ~/.bashrc -a ~/.zshrc |
20 |
| -``` |
| 20 | + |
| 21 | + ```bash |
| 22 | + echo export TEAM_NAME="<TEAM_NAME>" | tee -a ~/.bashrc -a ~/.zshrc |
| 23 | + ``` |
21 | 24 |
|
22 | 25 | 5. Add the `CLUSTER_DOMAIN` to the environment:
|
23 |
| -```bash |
24 |
| -echo export CLUSTER_DOMAIN="<CLUSTER_DOMAIN>" | tee -a ~/.bashrc -a ~/.zshrc |
25 |
| -``` |
| 26 | + |
| 27 | + ```bash |
| 28 | + echo export CLUSTER_DOMAIN="<CLUSTER_DOMAIN>" | tee -a ~/.bashrc -a ~/.zshrc |
| 29 | + ``` |
26 | 30 |
|
27 | 31 | 6. Add the `GIT_SERVER` to the environment:
|
28 |
| -```bash |
29 |
| -echo export GIT_SERVER="<GIT_SERVER>" | tee -a ~/.bashrc -a ~/.zshrc |
30 |
| -``` |
| 32 | + |
| 33 | + ```bash |
| 34 | + echo export GIT_SERVER="<GIT_SERVER>" | tee -a ~/.bashrc -a ~/.zshrc |
| 35 | + ``` |
31 | 36 |
|
32 | 37 | 7. Verify the variables you have set:
|
33 |
| -```bash |
34 |
| -source ~/.zshrc |
35 |
| -echo ${TEAM_NAME} |
36 |
| -echo ${CLUSTER_DOMAIN} |
37 |
| -echo ${GIT_SERVER} |
38 |
| -``` |
| 38 | + |
| 39 | + ```bash |
| 40 | + source ~/.zshrc |
| 41 | + echo ${TEAM_NAME} |
| 42 | + echo ${CLUSTER_DOMAIN} |
| 43 | + echo ${GIT_SERVER} |
| 44 | + ``` |
39 | 45 |
|
40 | 46 | 8. Check if you can connect to OpenShift. Run the command below.
|
41 | 47 |
|
42 |
| -<p class="tip"> |
43 |
| - β·οΈ <b>TIP</b> β·οΈ - Before you hit enter, make sure you change the username and password to match your team's login details </p> |
| 48 | + <p class="tip"> |
| 49 | + β·οΈ <b>TIP</b> β·οΈ - Before you hit enter, make sure you change the username and password to match your team's login details |
| 50 | + </p> |
44 | 51 |
|
45 |
| -```bash |
46 |
| -oc login --server=https://api.${CLUSTER_DOMAIN##apps.}:6443 -u <USERNAME> -p <PASSWORD> |
47 |
| -``` |
| 52 | + ```bash |
| 53 | + oc login --server=https://api.${CLUSTER_DOMAIN##apps.}:6443 -u <USERNAME> -p <PASSWORD> |
| 54 | + ``` |
48 | 55 |
|
49 | 56 | 9. Check your user permissions in OpenShift by creating your team's `ci-cd` project.
|
50 |
| -```bash |
51 |
| -oc new-project ${TEAM_NAME}-ci-cd |
52 |
| -``` |
53 |
| - |
54 | 57 |
|
55 |
| -<p class="warn"> |
56 |
| - β·οΈ <b>NOTE</b> β·οΈ - If you are working as a team and are using the same TEAM_NAME, you may receive a message saying this project already exists. One of your team mates would have already created this project. It's all good! |
57 |
| - </p> |
| 58 | + ```bash |
| 59 | + oc new-project ${TEAM_NAME}-ci-cd |
| 60 | + ``` |
| 61 | + |
| 62 | +  |
| 63 | + |
| 64 | + <p class="warn"> |
| 65 | + β·οΈ <b>NOTE</b> β·οΈ - If you are working as a team and are using the same TEAM_NAME, you may receive a message saying this project already exists. One of your team mates would have already created this project. It's all good! |
| 66 | + </p> |
58 | 67 |
|
59 | 68 | ### Helm 101
|
| 69 | +
|
60 | 70 | > Helm is the package manager for Kubernetes. It provides a way to create templates for the Kubernetes YAML that defines our application. The Kubernetes resources such as `DeploymentConfig`, `Route` & `Service` can be processed by supplying `values` to the templates. In Helm land, there are a few ways to do this. A package containing the templates and their default values is called a `chart`.
|
61 | 71 |
|
62 | 72 | Let's deploy a simple application using Helm.
|
63 | 73 |
|
64 | 74 | 1. Helm charts are packaged and stored in repositories. They can be added as dependencies of other charts or used directly. Let's add a chart repository now. The chart repository stores the version history of our charts as well as the packaged tar file.
|
65 |
| -```bash |
66 |
| -helm repo add tl500 https://rht-labs.com/todolist/ |
67 |
| -``` |
| 75 | +
|
| 76 | + ```bash |
| 77 | + helm repo add tl500 https://rht-labs.com/todolist/ |
| 78 | + ``` |
68 | 79 |
|
69 | 80 | 2. Let's install a chart from this repo. First search the repository to see what is available.
|
70 |
| -```bash |
71 |
| -helm search repo todolist |
72 |
| -``` |
73 | 81 |
|
74 |
| -Now install the latest version. Helm likes to give each install a release, for convenience we've set ours to `my`. This will add a prefix of `my-` to all the resources that are created. |
75 |
| -```bash |
76 |
| -helm install my tl500/todolist --namespace ${TEAM_NAME}-ci-cd |
77 |
| -``` |
| 82 | + ```bash |
| 83 | + helm search repo todolist |
| 84 | + ``` |
| 85 | + |
| 86 | + Now install the latest version. Helm likes to give each install a release, for convenience we've set ours to `my`. This will add a prefix of `my-` to all the resources that are created. |
| 87 | +
|
| 88 | + ```bash |
| 89 | + helm install my tl500/todolist --namespace ${TEAM_NAME}-ci-cd |
| 90 | + ``` |
78 | 91 |
|
79 | 92 | 3. Open the application up in the browser to verify it's up and running. Here's a handy one-liner to get the address of the app
|
80 |
| -```bash |
81 |
| -echo https://$(oc get route/my-todolist -n ${TEAM_NAME}-ci-cd --template='{{.spec.host}}') |
82 |
| -``` |
83 |
| - |
84 | 93 |
|
| 94 | + ```bash |
| 95 | + echo https://$(oc get route/my-todolist -n ${TEAM_NAME}-ci-cd --template='{{.spec.host}}') |
| 96 | + ``` |
| 97 | +
|
| 98 | +  |
| 99 | +
|
| 100 | +4. You can overwrite the default <span style="color:blue;">[values](https://github.com/rht-labs/todolist/blob/master/chart/values.yaml)</span> in a chart from the command line. Let's upgrade our deployment to show this. We'll make a simple change to the values to scale up our app. By default, we only have 1 replica. |
| 101 | +
|
| 102 | + ```bash |
| 103 | + oc get pods -n ${TEAM_NAME}-ci-cd |
| 104 | + ``` |
| 105 | +
|
| 106 | + By default, we only have one replica of our application. Let's use helm to set this to 5. |
85 | 107 |
|
86 |
| -4. You can overwrite the default <span style="color:blue;">[values](https://github.com/rht-labs/todolist/blob/master/chart/values.yaml)</span> in a chart from the command line. Let's upgrade our deployment to show this. We'll make a simple change to the values to scale up our app. By default, we only have 1 replica. |
87 |
| -```bash |
88 |
| -oc get pods -n ${TEAM_NAME}-ci-cd |
89 |
| -``` |
| 108 | + ```bash |
| 109 | + helm upgrade my tl500/todolist --set replicas=5 --namespace ${TEAM_NAME}-ci-cd |
| 110 | + ``` |
90 | 111 |
|
91 |
| -By default, we only have one replica of our application. Let's use helm to set this to 5. |
92 |
| -```bash |
93 |
| -helm upgrade my tl500/todolist --set replicas=5 --namespace ${TEAM_NAME}-ci-cd |
94 |
| -``` |
| 112 | + Verify the deployment has scaled up to 5 replicas. |
95 | 113 |
|
96 |
| -Verify the deployment has scaled up to 5 replicas. |
97 |
| -```bash |
98 |
| -oc get pods -n ${TEAM_NAME}-ci-cd |
99 |
| -``` |
| 114 | + ```bash |
| 115 | + oc get pods -n ${TEAM_NAME}-ci-cd |
| 116 | + ``` |
100 | 117 |
|
101 | 118 | 5. If you're done playing with the #amazing-todolist-app then let's tidy up our work by removing the chart. To do this, run helm uninstall to remove our release of the chart.
|
102 |
| -```bash |
103 |
| -helm uninstall my --namespace ${TEAM_NAME}-ci-cd |
104 |
| -``` |
105 |
| -Verify the clean up |
106 |
| -```bash |
107 |
| -oc get pods -n ${TEAM_NAME}-ci-cd | grep todolist |
108 |
| -``` |
109 |
| -<!--@Cansu - this is how you style a colour on a word mid sentence <span style="color:purple;" >zsh</span> --> |
| 119 | + |
| 120 | + ```bash |
| 121 | + helm uninstall my --namespace ${TEAM_NAME}-ci-cd |
| 122 | + ``` |
| 123 | + |
| 124 | + Verify the clean up |
| 125 | + |
| 126 | + ```bash |
| 127 | + oc get pods -n ${TEAM_NAME}-ci-cd | grep todolist |
| 128 | + ``` |
| 129 | + |
110 | 130 | 6. For those who are really interested, this is the anatomy of our Helm chart. It can be <span style="color:blue;">[found here](https://github.com/rht-labs/todolist)</span>, but the basic structure is as follows:
|
111 |
| -<div class="highlight" style="background: #f7f7f7"> |
112 |
| -<pre><code class="language-bash"> |
113 |
| -todolist/chart |
114 |
| -βββ Chart.yaml |
115 |
| -βββ templates |
116 |
| -βΒ Β βββ _helpers.tpl |
117 |
| -βΒ Β βββ deploymentconfig.yaml |
118 |
| -βΒ Β βββ route.yaml |
119 |
| -βΒ Β βββ service.yaml |
120 |
| -βββ values.yaml |
121 |
| -</code></pre></div> |
122 |
| -where: |
123 |
| -* `Chart.yaml` - is the manifest of the chart. It defines the name, version and dependencies for our chart. |
124 |
| -* `values.yaml` - is the sensible defaults for our chart to work, it contains the variables that are passed to the templates. We can overwrite these values on the command line. |
125 |
| -* `templates/*.yaml` - they are our k8s resources. |
126 |
| -* `_helpers.tpl` - is a collection of reusable variables an yaml snippets that are applied across all of the k8s resources uniformly for example, labels are defined in here and included on each k8s resource file as necessary. |
| 131 | + |
| 132 | + <div class="highlight" style="background: #f7f7f7"> |
| 133 | + <pre><code class="language-bash"> |
| 134 | + todolist/chart |
| 135 | + βββ Chart.yaml |
| 136 | + βββ templates |
| 137 | + βΒ Β βββ _helpers.tpl |
| 138 | + βΒ Β βββ deploymentconfig.yaml |
| 139 | + βΒ Β βββ route.yaml |
| 140 | + βΒ Β βββ service.yaml |
| 141 | + βββ values.yaml |
| 142 | + </code></pre></div> |
| 143 | + |
| 144 | + where: |
| 145 | + * `Chart.yaml` - is the manifest of the chart. It defines the name, version and dependencies for our chart. |
| 146 | + * `values.yaml` - is the sensible defaults for our chart to work, it contains the variables that are passed to the templates. We can overwrite these values on the command line. |
| 147 | + * `templates/*.yaml` - they are our k8s resources. |
| 148 | + * `_helpers.tpl` - is a collection of reusable variables an yaml snippets that are applied across all of the k8s resources uniformly for example, labels are defined in here and included on each k8s resource file as necessary. |
127 | 149 |
|
128 | 150 | πͺπͺ Now, let's continue with even more exciting tools... !πͺπͺ
|
0 commit comments