Overview
You can configure containerd additionally by creating configuration files using the NodeGroupConfiguration resource.
The containerd settings are handled by the built-in 032_configure_containerd.sh script. It merges all containerd service configuration files located at /etc/containerd/conf.d/*.toml and restarts the service.
When developing a NodeGroupConfiguration, keep in mind the following:
- The
/etc/containerd/conf.d/directory is not created automatically; - Files in this directory must be created before
032_configure_containerd.shruns, that is, with a priority lower than32.
Additional containerd settings
You can configure containerd on the nodes with NodeGroupConfiguration.
Adding custom settings causes the containerd service to restart.
You can override the values of parameters defined in the /etc/containerd/deckhouse.toml file, but you are then responsible for their correct operation. Avoid making changes that may affect master nodes.
Enabling containerd metrics
The simplest example of adding containerd settings is enabling metrics.
Note the following:
- The script creates a directory for configuration files.
- The script creates a file in the
/etc/containerd/conf.ddirectory. - The script has priority 31 (
weight: 31). - The configuration is not changed on master nodes, only on nodes of the
workergroup. - Metrics collection must be configured separately; this only enables the metrics.
- The script uses the bashbooster bb-sync-file construct to synchronize the file contents.
apiVersion: deckhouse.io/v1alpha1
kind: NodeGroupConfiguration
metadata:
name: containerd-enable-metrics.sh
spec:
bundles:
- '*'
content: |
mkdir -p /etc/containerd/conf.d
bb-sync-file /etc/containerd/conf.d/metrics_settings.toml - << EOF
[metrics]
address = "127.0.0.1"
grpc_histogram = true
EOF
nodeGroups:
- "worker"
weight: 31Adding a private registry with authorization
Running your own applications may require a private registry that may be protected by authorization. containerd allows you to configure registry settings using the plugins."io.containerd.grpc.v1.cri".registry parameter.
Authorization data is specified in the auth parameter in the docker registry auth format as a Base64 string. You can get the string with the following command:
d8 k create secret docker-registry my-secret --dry-run=client --docker-username=User --docker-password=password --docker-server=private.registry.example -o jsonpath="{ .data['\.dockerconfigjson'] }"
eyJhdXRocyI6eyJwcml2YXRlLnJlZ2lzdHJ5LmV4YW1wbGUiOnsidXNlcm5hbWUiOiJVc2VyIiwicGFzc3dvcmQiOiJwYXNzd29yZCIsImF1dGgiOiJWWE5sY2pwd1lYTnpkMjl5WkE9PSJ9fX0=Example NodeGroupConfiguration:
apiVersion: deckhouse.io/v1alpha1
kind: NodeGroupConfiguration
metadata:
name: containerd-additional-config.sh
spec:
bundles:
- '*'
content: |
REGISTRY_URL=private.registry.example
mkdir -p /etc/containerd/conf.d
bb-sync-file /etc/containerd/conf.d/additional_registry.toml - << EOF
[plugins]
[plugins."io.containerd.grpc.v1.cri"]
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."${REGISTRY_URL}"]
endpoint = ["https://${REGISTRY_URL}"]
[plugins."io.containerd.grpc.v1.cri".registry.configs."${REGISTRY_URL}".auth]
auth = "eyJhdXRocyI6eyJwcml2YXRlLnJlZ2lzdHJ5LmV4YW1wbGUiOnsidXNlcm5hbWUiOiJVc2VyIiwicGFzc3dvcmQiOiJwYXNzd29yZCIsImF1dGgiOiJWWE5sY2pwd1lYTnpkMjl5WkE9PSJ9fX0="
EOF
nodeGroups:
- "*"
weight: 31Adding a certificate for an additional registry
A private registry may require a root certificate. Add it to the /var/lib/containerd/certs directory and specify it in the tls parameter of the containerd settings.
You can base such a script on the instructions for adding a root certificate to the OS. Note the differences:
- The priority value is 31;
- The root certificate is added to the
/var/lib/containerd/certsdirectory; - The certificate path is added to the
plugins."io.containerd.grpc.v1.cri".registry.configs."${REGISTRY_URL}".tlssettings section.
The script uses the following bashbooster constructs:
- bb-sync-file to synchronize the file contents.
- bb-tmp-file to create temporary files and delete them after the script runs.
apiVersion: deckhouse.io/v1alpha1
kind: NodeGroupConfiguration
metadata:
name: configure-cert-containerd.sh
spec:
bundles:
- '*'
nodeGroups:
- '*'
weight: 31
content: |-
REGISTRY_URL=private.registry.example
CERT_FILE_NAME=${REGISTRY_URL}
CERTS_FOLDER="/var/lib/containerd/certs/"
CERT_CONTENT=$(cat <<"EOF"
-----BEGIN CERTIFICATE-----
MIIDSjCCAjKgAwIBAgIRAJ4RR/WDuAym7M11JA8W7D0wDQYJKoZIhvcNAQELBQAw
JTEjMCEGA1UEAxMabmV4dXMuNTEuMjUwLjQxLjIuc3NsaXAuaW8wHh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EOF
[plugins]
[plugins."io.containerd.grpc.v1.cri".registry.configs."${REGISTRY_URL}".tls]
ca_file = "${CERTS_FOLDER}/${CERT_FILE_NAME}.crt"
EOF
)
mkdir -p ${CERTS_FOLDER}
mkdir -p /etc/containerd/conf.d
CERT_TMP_FILE="$( bb-tmp-file )"
echo -e "${CERT_CONTENT}" > "${CERT_TMP_FILE}"
CONFIG_TMP_FILE="$( bb-tmp-file )"
echo -e "${CONFIG_CONTENT}" > "${CONFIG_TMP_FILE}"
# Ensure CA certificate file in the CERTS_FOLDER.
bb-sync-file \
"${CERTS_FOLDER}/${CERT_FILE_NAME}.crt" \
${CERT_TMP_FILE}
# Ensure additional containerd configuration file.
bb-sync-file \
"/etc/containerd/conf.d/${REGISTRY_URL}.toml" \
${CONFIG_TMP_FILE}