Ce contenu n'est pas disponible dans la langue sélectionnée.
Chapter 1. Using Kustomize manifests to deploy applications
You can use the kustomize
configuration management tool with application manifests to deploy applications. Read through the following procedures for an example of how Kustomize works in MicroShift.
1.1. How Kustomize works with manifests to deploy applications
The kustomize
configuration management tool is integrated with MicroShift. You can use Kustomize and the OpenShift CLI (oc
) together to apply customizations to your application manifests and deploy those applications to a MicroShift cluster.
-
A
kustomization.yaml
file is a specification of resources plus customizations. -
Kustomize uses a
kustomization.yaml
file to load a resource, such as an application, then applies any changes you want to that application manifest and produces a copy of the manifest with the changes overlaid. - Using a manifest copy with an overlay keeps the original configuration file for your application intact, while enabling you to deploy iterations and customizations of your applications efficiently.
-
You can then deploy the application in your MicroShift cluster with an
oc
command.
1.1.1. How MicroShift uses manifests
At every start, MicroShift searches the following manifest directories for Kustomize manifest files:
-
/etc/microshift/manifests
-
/etc/microshift/manifests.d/*
-
/usr/lib/microshift/
-
/usr/lib/microshift/manifests.d/*
MicroShift automatically runs the equivalent of the kubectl apply -k
command to apply the manifests to the cluster if any of the following file types exists in the searched directories:
-
kustomization.yaml
-
kustomization.yml
-
Kustomization
This automatic loading from multiple directories means you can manage MicroShift workloads with the flexibility of having different workloads run independently of each other.
Location | Intent |
---|---|
| Read-write location for configuration management systems or development. |
| Read-write location for configuration management systems or development. |
| Read-only location for embedding configuration manifests on OSTree-based systems. |
| Read-only location for embedding configuration manifests on OSTree-based systems. |
1.2. Override the list of manifest paths
You can override the list of default manifest paths by using a new single path, or by using a new glob pattern for multiple files. Use the following procedure to customize your manifest paths.
Procedure
Override the list of default paths by inserting your own values and running one of the following commands:
-
Set
manifests.kustomizePaths
to<"/opt/alternate/path">
in the configuration file for a single path. Set
kustomizePaths
to,"/opt/alternative/path.d/*".
in the configuration file for a glob pattern.manifests: kustomizePaths: - <location> 1
- 1
- Set each location entry to an exact path by using
"/opt/alternate/path"
or a glob pattern by using"/opt/alternative/path.d/*"
.
-
Set
To disable loading manifests, set the configuration option to an empty list.
manifests: kustomizePaths: []
NoteThe configuration file overrides the defaults entirely. If the
kustomizePaths
value is set, only the values in the configuration file are used. Setting the value to an empty list disables manifest loading.
1.3. Using manifests example
This example demonstrates automatic deployment of a BusyBox container using kustomize
manifests in the /etc/microshift/manifests
directory.
Procedure
Create the BusyBox manifest files by running the following commands:
Define the directory location:
$ MANIFEST_DIR=/etc/microshift/manifests
Make the directory:
$ sudo mkdir -p ${MANIFEST_DIR}
Place the YAML file in the directory:
sudo tee ${MANIFEST_DIR}/busybox.yaml &>/dev/null <<EOF apiVersion: v1 kind: Namespace metadata: name: busybox --- apiVersion: apps/v1 kind: Deployment metadata: name: busybox namespace: busybox-deployment spec: selector: matchLabels: app: busybox template: metadata: labels: app: busybox spec: containers: - name: busybox image: BUSYBOX_IMAGE command: [ "/bin/sh", "-c", "while true ; do date; sleep 3600; done;" ] EOF
Next, create the
kustomize
manifest files by running the following commands:Place the YAML file in the directory:
sudo tee ${MANIFEST_DIR}/kustomization.yaml &>/dev/null <<EOF apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization namespace: busybox resources: - busybox.yaml images: - name: BUSYBOX_IMAGE newName: busybox:1.35 EOF
Restart MicroShift to apply the manifests by running the following command:
$ sudo systemctl restart microshift
Apply the manifests and start the
busybox
pod by running the following command:$ oc get pods -n busybox