分享一个很香的k8s.gcr.io Docker镜像拉取方法
k8s.gcr.io拉取镜像
·
经常k8s.gcr.io
,quay.io
之类的国外镜像拉取不过来,那怎么办呢?
本文安利一种使用github action拉取镜像推送到Dockerhub的方法。推送好了之后,自己拉取镜像retag一下就能用了
编译kubernetes源码需要好几个国外镜像,我的构建服务器根本连不上
k8s.gcr.io
, -_-!!!
比如我现在要拉取的镜像叫做k8s.gcr.io/build-image/kube-cross:v1.21.0-go1.16.15-buster.0
.
1. 创建一个Github仓库
创建一个github仓库,并初始化Action.
2. 创建DockerHub Secret
一定要用Repository Secret类型,上面的Environment Secret是我建错了,根本不好使!!
3. 编写你的ci yaml文件为
底下的代码都有注释,大概思路就是
- 让github的服务器拉取
k8s.gcr.io
的镜像 - 登录你的dockerhub账户
- 重新tag一下拉取的镜像为你仓库的tag
- 推送到dockerhub
# This is a basic workflow to help you get started with Actions
name: CI
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
# Runs a set of commands using the runners shell
- name: Run a multi-line script
run: |
docker pull k8s.gcr.io/build-image/kube-cross:v1.21.0-go1.16.15-buster.0
docker tag k8s.gcr.io/build-image/kube-cross:v1.21.0-go1.16.15-buster.0 oneslide/k8s.gcr.io:kube-cross-v1.21.0-go1.16.15-buster.0
- name: Log in to Docker Hub
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
# Runs a set of commands using the runners shell
- name: Push to Docker Registry
run: |
docker push oneslide/k8s.gcr.io:kube-cross-v1.21.0-go1.16.15-buster.0
4. 观察gitlab CI输出
Reference List
- https://docs.github.com/en/actions/publishing-packages/publishing-docker-images
更多推荐
已为社区贡献7条内容
所有评论(0)