1.3. 使用清单示例
本例演示了使用 /etc/microshift/manifests
目录中的 kustomize
清单自动部署 BusyBox 容器。
流程
运行以下命令来创建 BusyBox 清单文件:
定义目录位置:
$ MANIFEST_DIR=/etc/microshift/manifests
创建目录:
$ sudo mkdir -p ${MANIFEST_DIR}
将 YAML 文件放在目录中:
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
接下来,运行以下命令来创建
kustomize
清单文件:将 YAML 文件放在目录中:
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
运行以下命令重启 MicroShift 以应用清单:
$ sudo systemctl restart microshift
运行以下命令应用清单并启动
busybox
pod:$ oc get pods -n busybox