This article describes two approaches to configure custom OS packages in TKGi VMs.
Generally speaking, if a package is installed in a node and, afterwards, the node gets recreated, for example due to an upgrade, the recreated VM won't include the extra installed packages.
To circumvent this situation and make the installation of packages persistent, follow one of the approaches outlined below.
Note: any custom configuration made in the nodes, including installing non-default packages, is out of the scope of general Broadcom Support.
The recommended way to install OS packages persistently in TKGi nodes is through Bosh OS Configs.
These configs allow us to make persistent OS-level modifications in Bosh-managed deployments. A complete list of available jobs can be found here.
To install OS packages in TKGi nodes, a suitable job to configure would be post-deploy-script.
An example of this job is given in the link above and looks as follows:
name: post-deploy-script
templates:
post-deploy.sh: bin/post-deploy
packages: []
properties:
script:
description: Script that is run during post-deploy to allow additional setup of environment, run as root user.
example: |-
#!/bin/bash
apt-get update && apt-get install wget git tmux -y
The job will run automatically after the nodes/VMs have been provisioned and will install all the packages specified after the above "apt-get install" command.
If any further custom configuration is needed, for example adding custom repositories from where packages will be pulled, this can also be included in the post-deploy-script.
To configure the above:
# bosh upload-release --sha1 d20772d8ce6e781ceb13cac7df5950bfa4330ba1 "https://bosh.io/d/github.com/cloudfoundry/os-conf-release?v=23.0.0"
# vim runtime.yml
releases:
- name: "os-conf"
version: "23.0.0"
addons:
- name: os-configuration
jobs:
- name: post-deploy-script
release: os-conf
properties:
script: |-
#!/bin/bash
apt-get update && apt-get install wget git tmux -y
include:
deployments: [<service-instance_XXXXXXXXXX>] # Optional, you can define which deployments (TKGi clusters) this runtime config will be applied to.
instance_groups: [<master and/or worker, as defined in the deployment manifest>] # Optional,
you can define which instance_groups (cluster nodes, i.e. masters/workers) this runtime config will be applied to.
exclude:
deployments: [<service-instance_XXXXXXXXXX>] # Optional,
you can define which deployments (TKGi clusters) this runtime config will not be applied to.
instance_groups: [<master and/or worker, as defined in the deployment manifest>] # Optional,
you can define which instance_groups (cluster nodes, i.e. masters/workers) this runtime config will not be applied to.
# bosh update-runtime-config runtime.yml
# bosh runtime-config
# tkgi upgrade-cluster <cluster-name>
If Approach #1 is not suitable, this approach consists in deploying a DaemonSet that will perform the installation of the packages in all the nodes in the cluster.
Please note that Approach #1 is the preferred one as it uses Bosh native capabilities, while this approach relies on custom pods running in the clusters, consuming extra resources and more prone to causing unexpected issues.
# vim daemonset.yaml
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: node-init
namespace: node-init
spec:
selector:
matchLabels:
name: node-init
template:
metadata:
labels:
name: node-init
spec:
nodeSelector: ## this field is optional, if you want to install packages just in certain nodes
<node-key>: "<node-value" ## this field is optional, if you want to install packages just in certain nodes
initContainers:
- name: node-init
image: <registry>/busybox:latest
securityContext:
privileged: true
command: ["/bin/sh"]
args: ["-c", "apt-get update && apt-get install wget git tmux
-y"]
containers:
- name: sleep
image: <registry>/pause:3.9
# kubectl apply -f daemonset.yaml
# kubectl get po -n node-init