Building Images Using OCI Connector in K8S Job
Before reading, please refer to The General Logic of Using the OCI Connector Proxy in K8S Workload
TOC
Feature Overview
This article will guide you on how to use the OCI Connector to build images within a Kubernetes Job and push them to a Registry. With the capabilities of the OCI Connector, ordinary users can operate without needing to touch or configure authentication credentials, thereby maximizing the security of these credentials.
When using the OCI Connector within a Kubernetes Job, the following key points should be noted:
- Change the address of the target image being built to the connector's proxy address. What is the Connector Proxy Address
- For example: harbor.example.cn/test/abc:v1 -> harbor.default.cluster.local/test/abc:v1
- Mount the configuration provided by the Connector.
- Configure
insecure registryfor the client tools.
This article will take buildkitd as an example and detail the process of creating a Kubernetes Job to complete the image building and pushing utilizing the OCI Connector, without the need to configure authentication information on the client side.
Prerequisites
- Create a Connector.
- A Dockerfile for building the image.
Connector
Dockerfile
To demonstrate the building and pushing process, we need to prepare a Dockerfile. To simplify the operation, we will store the content of the Dockerfile in a ConfigMap and mount it to the Pod using a Kubernetes Pod volume.
Operational Steps
Creating the K8S Job
- To utilize the connector's proxy capabilities, we need to inject the authentication information required by the proxy into
docker/config.json. A volume must be provided to mountdocker/config.json. - To allow the client to access the HTTP proxy, we need to configure
insecure-registriesfor the client. A volume must be provided to mountbuildkitd.toml. - Modify the address of the pushed image to the connector's proxy address.
For information on obtaining the Connector's proxy address, see: OCI Connector Class Proxy Information Description
The Job content is as follows:
Operational Results
You can check whether the Job has executed successfully with the following command:
Summary
We have completed the entire process of "Building Images Using OCI Connector in K8S Job." We can observe that during the execution of the Job, users are required to specify the authentication information for the image repository, and within the Pod running the Job, users cannot access the authentication data configured for the Connector. This greatly ensures that credentials are not leaked in practical usage, safeguarding the security of the tool's authentication information.