且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 Google Container Engine 上运行私有 docker 镜像

更新时间:2023-11-24 18:19:22

您可以将您的图片推送到 Google Container Registry 并从您的 pod 清单中引用它们.

You can push your image to Google Container Registry and reference them from your pod manifest.

假设您正确设置了 DOCKER_HOST 、运行最新版本 Kubernetes 的 GKE 集群和 已安装 Google Cloud SDK.

Assuming you have a DOCKER_HOST properly setup , a GKE cluster running the last version of Kubernetes and Google Cloud SDK installed.

  1. 设置一些环境变量

  1. Setup some environment variables

gcloud components update kubectl
gcloud config set project <your-project>
gcloud config set compute/zone <your-cluster-zone>
gcloud config set container/cluster <your-cluster-name>
gcloud container clusters get-credentials <your-cluster-name>

  • 标记您的图片

  • Tag your image

    docker tag <your-image> gcr.io/<your-project>/<your-image>
    

  • 推送你的图片

  • Push your image

    gcloud docker push gcr.io/<your-project>/<your-image>
    

  • 为您的容器创建一个 pod 清单:my-pod.yaml

    id: my-pod
    kind: Pod
    apiVersion: v1
    desiredState:
      manifest:
        containers:
        - name: <container-name>
          image: gcr.io/<your-project>/<your-image>
        ...
    

  • 安排此 Pod

  • Schedule this pod

    kubectl create -f my-pod.yaml
    

  • 从第 (4) 步开始对您要运行的每个 Pod 重复.您可以使用带有 --- 作为分隔符的行在单个文件中包含多个定义.

  • Repeat from step (4) for each pod you want to run. You can have multiple definitions in a single file using a line with --- as delimiter.