リンク上の元の推薦クリック下のより良い読書体験。
オリジナル住所:のhttp://maoqide.live/post/cloud/build-docker-image-in-a-pod-in-kubernetes/
使用kanikoの kubernetesクラスタでの使用ポッドミラーを構築し、ミラーリポジトリにプッシュします。
事前のリクエスト
- クラスタkubernetes
- kaniko-executor image
の構築
具体的な使用量は読むことができますkanikoプロジェクト自体でサポートされているREADMEドキュメンテーションプロジェクト、GCS Bucket
、S3 Bucket
、Local Directory
、Git Repository
4種類buildcontextストレージソリューションを、実際の使用では、内部のファイルサーバを使用した感はより便利で、httpsを直接ダウンロードリンクhttp /およびhttpsのサポートを追加://github.com/maoqide/kaniko。
クイックスタート
自分でkanikoエグゼキュータのためのイメージを構築
# build yourself a image for kaniko executor
cd $GOPATH/src/github.com/GoogleContainerTools
git clone https://github.com/maoqide/kaniko
make images
buildcontextのためにHTTP / HTTPSを使用している場合は、ファイル・サーバを起動します
kaniko's build context is very similar to the build context you would send your Docker daemon for an image build; it represents a directory containing a Dockerfile which kaniko will use to build your image. For example, a COPY command in your Dockerfile should refer to a file in the build context.
使用してminioをファイルサーバとして:
docker run -p 9000:9000 minio/minio server /data
context.tar.gzを作成します
# tar your build context including Dockerfile into context.tar.gz
tar -C <path to build context> -zcvf context.tar.gz .
minioにアップロードおよびダウンロードURLを生成します。
秘密kubernetesを作成します。
# registry can also be a harbor or other registry.
kubectl create secret docker-registry regcred --docker-server=<your-registry-server> --docker-username=<your-name> --docker-password=<your-pword> --docker-email=<your-email>
ポッドを作成します
apiVersion: v1
kind: Pod
metadata:
name: kaniko
spec:
containers:
- name: kaniko
env:
- name: DOCKER_CONFIG
value: /root/.docker/
image: harbor.guahao-inc.com/mqtest/executor
args: [ "--context=http://download_url/context.tar.gz",
"--destination=maoqide/test:latest",
"--verbosity=debug",
]
volumeMounts:
- name: kaniko-secret
mountPath: /root
- name: context
mountPath: /kaniko/buildcontext/
restartPolicy: Never
volumes:
- name: context
emptyDir: {}
- name: kaniko-secret
secret:
secretName: regcred
items:
- key: .dockerconfigjson
path: .docker/config.json
ENV DOCKER_CONFIGは、そうでなければ、不正なエラーになるだろう、regidtry許可に必要です。
kubectl create -f pod.yaml
[root@centos10 ~]$ kubectl get po
NAME READY STATUS RESTARTS AGE
kaniko 0/1 Completed 0 5h
あなたは、あなたのイメージをプッシュ見つけることができます。