Building Cluster Images Based on the Image List
This document will guide you on how to build cluster images using the image list, including how to build a single image (based on pre-existing Kubernetes images) or build an application image from scratch.
Directory Structure
.
├── Kubefile
├── cni
│ ├── custom-resources.yaml
│ └── tigera-operator.yaml
├── images
│ └── shim
│ └── CalicoImageList
└── registry
└── docker
└── registry
Dockerfile Building
We can build all content into a single image (FROM labring/kubernetes
) or use FROM scratch
to build the image from scratch.
Single Image
FROM labring/kubernetes:v1.24.0
COPY cni ./cni
COPY images ./images
COPY registry ./registry
CMD ["kubectl apply -f cni/tigera-operator.yaml","kubectl apply -f cni/custom-resources.yaml"]
Application Image
This image does not include Kubernetes, so it should run in a cluster where Kubernetes is already installed.
FROM scratch
COPY cni ./cni
COPY images ./images
COPY registry ./registry
COPY manifests ./manifests
CMD ["kubectl apply -f cni/tigera-operator.yaml","kubectl apply -f cni/custom-resources.yaml"]
Notes:
CalicoImageList
: Docker image list file.cni
: Configuration files forkubectl apply
.registry
: Directory for storing container registry data.sealos build -t kubernetes-calico:1.24.0-amd64 --platform linux/amd64 -f Kubefile .
: Command for building the OCI image.manifests
: Resolve images in the yaml file to a Docker image list.
Building Calico Image
Directory Structure
.
├── Kubefile
├── cni
│ ├── custom-resources.yaml
│ └── tigera-operator.yaml
Dockerfile Building
All Together
This image includes both Kubernetes and Calico.
FROM labring/kubernetes:v1.24.0-amd64
COPY cni ./cni
CMD ["kubectl apply -f cni/tigera-operator.yaml","kubectl apply -f cni/custom-resources.yaml"]
Application Image
This image only contains Calico.
FROM scratch
COPY cni ./cni
CMD ["kubectl apply -f cni/tigera-operator.yaml","kubectl apply -f cni/custom-resources.yaml"]
Notes:
cni
: Configuration files forkubectl apply
.sealos build -t kubernetes-calico:1.24.0-amd64 --platform linux/amd64 -f Kubefile .
: Command for building the OCI image.
Building OpenEBS Image
Directory Structure
.
├── Kubefile
├── cni
│ ├── custom-resources.yaml
│ └── tigera-operator.yaml
└── manifests
└── openebs-operator.yaml
Dockerfile Building
All Together
FROM labring/oci-kubernetes-calico:1.24.0-amd64
COPY cni ./cni
COPY manifests ./manifests
CMD ["kubectl apply -f cni/tigera
-operator.yaml","kubectl apply -f cni/custom-resources.yaml","kubectl apply -f manifests/openebs-operator.yaml"]
Application Image
FROM scratch
COPY cni ./cni
COPY manifests ./manifests
CMD ["kubectl apply -f manifests/openebs-operator.yaml"]
Notes:
cni
: Configuration files forkubectl apply
.sealos build -t labring/kubernetes-calico-openebs:1.24.0-amd64 --platform linux/amd64 -f Kubefile .
: Command for building the OCI image.
Recommendation: You need to add the CMD of Calico to the CMD layer of OpenEBS because the Dockerfile will overwrite older layers.