Skip to content

Commit bf5e6c3

Browse files
authored
Updated docs for cloud-init (#554)
* docs: provided detailed cloud-init instructions Signed-off-by: sandeep <sandeep0814@gmail.com>
1 parent 2eeacf1 commit bf5e6c3

File tree

5 files changed

+48
-96
lines changed

5 files changed

+48
-96
lines changed

README.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
:uri-terraform-hashircorp-examples: https://github.com/hashicorp/terraform-guides/tree/master/infrastructure-as-code/terraform-0.12-examples
3838
:uri-topology: {uri-docs}/topology.adoc
3939
:uri-upgrade: {uri-docs}/upgrade.adoc
40+
:uri-cloudinit: {uri-docs}/cloudinit.adoc
4041

4142
{uri-oke}[Oracle Container Engine] (OKE) is {uri-oracle}[Oracle]'s managed {uri-kubernetes}[Kubernetes] service on {uri-oci}[Oracle Cloud Infrastructure (OCI)].
4243
@@ -54,6 +55,8 @@ This {uri-repo}[Terraform OKE Installer] for {uri-oci}[Oracle Cloud Infrastructu
5455
5556
* {uri-topology}[Topology]
5657
58+
* {uri-cloudinit}[Configuring cloud-init]
59+
5760
* {uri-terraform-options}[Terraform Options]
5861
5962
* {uri-upgrade}[Upgrading OKE]

docs/cloudinit.adoc

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,59 @@
22
:idprefix:
33
:idseparator: -
44
:sectlinks:
5-
:sectnums:
65
:toc: auto
76

87
:uri-cloudinit: https://docs.oracle.com/en-us/iaas/Content/ContEng/Tasks/contengusingcustomcloudinitscripts.htm
8+
:uri-source-cloudinit-doc: https://github.com/oracle-terraform-modules/terraform-oci-oke/blob/main/docs/instructions.adoc#configuring-cloud-init-for-the-nodepools
9+
:uri-repo: https://github.com/oracle-terraform-modules/terraform-oci-oke
10+
:uri-worker-script: link:{uri-repo}/modules/oke/cloudinit/worker.template.sh
911

10-
== Instructions:
1112

12-
* {uri-cloudinit}[Using cloud-init in OKE]
13-
* The default cloud-init script used by this module is as below:
14-
----
15-
#!/bin/bash
13+
== Configuring cloud-init scripts for node pools:
14+
There are 2 types of cloud-init scripts that can be configured for node pools:
1615

17-
# DO NOT MODIFY
18-
curl --fail -H "Authorization: Bearer Oracle" -L0 http://169.254.169.254/opc/v2/instance/metadata/oke_init_script | base64 --decode >/var/run/oke-init.sh
16+
. Common: these are cloud-init scripts that are common to all node pools
17+
. Node pool specific: these are cloud-init scripts that are specific to particular node pools.
1918

20-
## run oke provisioning script
21-
bash -x /var/run/oke-init.sh
19+
=== Default cloud-init
2220

23-
### adjust block volume size
24-
/usr/libexec/oci-growfs -y
21+
By default, the {uri-worker-script}[worker template] is used. The default worker template runs `oci-growfs` and `timedatectl` to configure the boot volume size and timezone respectively.
2522

26-
timedatectl set-timezone ${worker_timezone}
27-
----
23+
=== Script precedence
24+
25+
If no value is configured for `cloudinit_nodepool_common` or for `cloudinit_nodepool`, this default template is used.
26+
27+
If a value is configured for `cloudinit_nodepool_common`, then this value is used instead.
28+
29+
If a value is configured for `cloudinit_nodepool`, then this value is used for the specific nodepool only instead. Other nodepools will utilize whatever script is common.
30+
31+
The flowchart below depicts the script selection workflow:
32+
33+
.cloud-init script selection
34+
image::images/cloud-init-flowchart.png[align="cloud-init script selection"]
2835

29-
* To customize this you can modify the above script and pass the script as input variable to `cloudinit_nodepool_common`. This script will be used across all the nodepools.
3036

31-
* To use specific cloud-init script for a nodepool pass the script as input variable to `cloudinit_nodepool` as a map.This will take precedence over `cloudinit_nodepool_common` for that nodepool.
32-
Ex: cloudinit_nodepool = {
33-
#np1 = "/tmp/np1cloudinit.sh"
34-
#np3 = "/tmp/np3cloudinit.sh"
35-
#}
37+
== Overriding default cloud-init
3638

39+
=== Overriding the common cloud-init
40+
41+
The common cloud-init script for all node pools can be overriden as follows:
42+
43+
```
44+
cloudinit_nodepool_common = "/tmp/cloudinit_nodepool_common.sh"
45+
```
46+
47+
=== Specifying a cloud-init script for specific node pools
48+
49+
Sometimes, it may be desirable to configure additional settings for specific node pools without affecting the behaviour of existing or other node pools. In this case, you can override cloud-init as follows:
50+
51+
----
52+
cloudinit_nodepool = {
53+
np1 = "/tmp/np1_cloud-init.sh"
54+
np3 = "/tmp/np3_cloud-init.sh"
55+
}
56+
----
3757

58+
In the above example, node pool `np1` and `np3` will use `/tmp/np1_cloud-init.sh` and `/tmp/np3_cloud-init.sh` respectively for their cloud-init.
3859

60+
NOTE: You must ensure that the node pool name specified for cloud-init matches those you defined in the `node_pools` variable.

docs/configuration.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
:uri-terraform-oke-sample: https://github.com/terraform-providers/terraform-provider-oci/tree/master/examples/container_engine
4343
:uri-terraform-options: {uri-docs}/terraformoptions.adoc
4444
:uri-topology: {uri-docs}/topology.adoc
45+
:uri-cloudinit: {uri-docs}/cloudinit.adoc
4546

4647
== Assumptions
4748

@@ -207,6 +208,8 @@ The OKE Node Pool parameters control the following:
207208

208209
An empty value for boot volume size will default the boot volume to 50GB. This value is updatable. However the effect will be effective in newly created nodes _only_.
209210

211+
Refer to {uri-cloudinit}[cloudinit] for specifying how to configure cloud-init scripts for nodepools.
212+
210213
Refer to {uri-topology}[topology] for more thorough examples.
211214

212215
== Configure OKE Load Balancer parameters

docs/images/cloud-init-flowchart.png

40.7 KB
Loading

docs/instructions.adoc

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -286,82 +286,6 @@ Scaling changes to the number and size of node pools are immediate after changin
286286

287287
Set the parameter *node_pools* to the desired quantities to scale the node pools accordingly. Refer to {uri-topology}#node-pools[Nodepool].
288288

289-
== Configuring cloud-init for the nodepools
290-
291-
To install additional packages, configure settings or execute certain extra commands on node pools, you can use cloud-init to do that for you.
292-
293-
By default, there is a `worker.template.sh` file under the cloudinit directory in the `oke` module. Follow the following steps to add your own:
294-
295-
. Add your own script in the cloudinit directory. An example is provided by `second.template.sh`. If you need to parameterize the script, enclose the parameter within `${}`. For example:
296-
297-
+
298-
----
299-
yum install -y package-${version}
300-
----
301-
302-
303-
. Declare your script as a template in the cloudinit.tf in the locals section. A corresponding example for the `second.template.sh` is provided.
304-
305-
+
306-
If you do *_not_* need to pass a parameter to the script, leave the 2^nd^ argument to the template file function as empty:
307-
308-
+
309-
----
310-
second_script_template = templatefile("${path.module}/cloudinit/second.template.sh",{})
311-
----
312-
313-
+
314-
Otherwise, pass a parameter to the template script as follows:
315-
316-
+
317-
----
318-
second_script_template = templatefile("${path.module}/cloudinit/second.template.sh",
319-
{
320-
version = "5.4.0"
321-
}
322-
)
323-
----
324-
325-
. Add the part in the `cloudinit_config worker` section:
326-
327-
+
328-
----
329-
part {
330-
filename = "second.sh"
331-
content_type = "text/x-shellscript"
332-
content = local.second_script_template
333-
}
334-
----
335-
336-
. You can add more scripts and have them loaded in the order you need. For example:
337-
338-
+
339-
----
340-
data "cloudinit_config" "worker" {
341-
gzip = false
342-
base64_encode = true
343-
344-
part {
345-
filename = "worker.sh"
346-
content_type = "text/x-shellscript"
347-
content = local.worker_script_template
348-
}
349-
350-
part {
351-
filename = "second.sh"
352-
content_type = "text/x-shellscript"
353-
content = local.second_script_template
354-
}
355-
356-
part {
357-
filename = "third.sh"
358-
content_type = "text/x-shellscript"
359-
content = local.third_script_template
360-
}
361-
}
362-
----
363-
364-
365289
== Accessing the Kubernetes dashboard
366290

367291
By default, the Kubernetes dashboard is now disabled. To enable it, set the *dashboard_enabled = true* _before_ creating the cluster. The dashboard will then be deployed.

0 commit comments

Comments
 (0)