docker - 部署到gcloud上的CircleCI kubectl配置错误

标签 docker kubernetes gcloud kubectl circleci

我通常是docker / kubernetes / dev ops的新手,我正在学习一个使用TravisGithub的类(class),但是我使用BitBucket,所以我尝试使用CircleCI将CI部署到GKE。

大多数任务都可以正常工作,但是当涉及到kubectl时(特别是在deploy.sh脚本上),我遇到了一个错误。这是我得到的错误:

unable to recognize "k8s/client-deployment.yml": Get http://localhost:8080/api?timeout=32s: dial tcp 127.0.0.1:8080: connect: connection refused
unable to recognize "k8s/database-persistent-volume-claim.yml": Get http://localhost:8080/api?timeout=32s: dial tcp 127.0.0.1:8080: connect: connection refused
unable to recognize "k8s/ingress-service.yml": Get http://localhost:8080/api?timeout=32s: dial tcp 127.0.0.1:8080: connect: connection refused
unable to recognize "k8s/postgres-cluster-ip-service.yml": Get http://localhost:8080/api?timeout=32s: dial tcp 127.0.0.1:8080: connect: connection refused
unable to recognize "k8s/postgres-deployment.yml": Get http://localhost:8080/api?timeout=32s: dial tcp 127.0.0.1:8080: connect: connection refused
unable to recognize "k8s/redis-cluster-ip-service.yml": Get http://localhost:8080/api?timeout=32s: dial tcp 127.0.0.1:8080: connect: connection refused
unable to recognize "k8s/redis-deployment.yml": Get http://localhost:8080/api?timeout=32s: dial tcp 127.0.0.1:8080: connect: connection refused
unable to recognize "k8s/server-cluster-ip-service.yml": Get http://localhost:8080/api?timeout=32s: dial tcp 127.0.0.1:8080: connect: connection refused
unable to recognize "k8s/server-deployment.yml": Get http://localhost:8080/api?timeout=32s: dial tcp 127.0.0.1:8080: connect: connection refused
unable to recognize "k8s/worker-deployment.yml": Get http://localhost:8080/api?timeout=32s: dial tcp 127.0.0.1:8080: connect: connection refused

我已经设法解决了很多问题,但是我对此一无所知,因此不胜感激。

这是CircleCI的config.yml(在MyUser上,我实际上使用的是docker用户,而不是env或其他任何东西,只是不公开它):
version: 2
jobs:
  build:
    docker:
      - image: node

    working_directory: ~/app

    steps:
      - checkout
      - setup_remote_docker

      - run:
          name: Install Docker Client
          command: |
            set -x
            VER="18.09.2"
            curl -L -o /tmp/docker-$VER.tgz https://download.docker.com/linux/static/stable/x86_64/docker-$VER.tgz
            tar -xz -C /tmp -f /tmp/docker-$VER.tgz
            mv /tmp/docker/* /usr/bin

      - run:
          name: Build Client Docker Image
          command: docker build -t MY_USER/multi-docker-react -f ./client/Dockerfile.dev ./client

      - run:
          name: Run Tests
          command: docker run -e CI=true MY_USER/multi-docker-react npm run test -- --coverage

  deploy:
    working_directory: ~/app
    # Docker environment where we gonna run our build deployment scripts 
    docker:
    - image: google/cloud-sdk

    steps:
    - checkout
    - setup_remote_docker:
        docker_layer_caching: true

    # Set up Env
    - run:
        name: Setup Environment Variables
        command: |
          echo 'export GIT_SHA="$CIRCLE_SHA1"' >> $BASH_ENV
          echo 'export CLOUDSDK_CORE_DISABLE_PROMPTS=1' >> $BASH_ENV

          # Log in to docker CLI
    - run:
        name: Log in to Docker Hub
        command: |
          echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_ID" --password-stdin

    # !!! This installs gcloud !!!
    - run:
        name: Installing GCL
        working_directory: /
        command: |
          echo $GCLOUD_SERVICE_KEY | gcloud auth activate-service-account --key-file=-
          gcloud --quiet config set project ${GOOGLE_PROJECT_ID}
          gcloud --quiet config set compute/zone ${GOOGLE_COMPUTE_ZONE}

    # !!! This runs a deployment
    - run:
        name: Deploying
        command: bash ./deploy.sh

workflows:
  version: 2
  build:
    jobs:
    - deploy:
        filters:
          branches:
            only:
            - master

这是deploy.sh:
docker build -t MY_USER/multi-docker-client:latest -t MY_USER/multi-docker-client:$GIT_SHA -f ./client/Dockerfile ./client
docker build -t MY_USER/multi-docker-server:latest -t MY_USER/multi-docker-server:$GIT_SHA -f ./server/Dockerfile ./server
docker build -t MY_USER/multi-docker-worker:latest -t MY_USER/multi-docker-worker:$GIT_SHA -f ./worker/Dockerfile ./worker
docker push MY_USER/multi-docker-client:latest
docker push MY_USER/multi-docker-server:latest
docker push MY_USER/multi-docker-worker:latest
docker push MY_USER/multi-docker-client:$GIT_SHA
docker push MY_USER/multi-docker-server:$GIT_SHA
docker push MY_USER/multi-docker-worker:$GIT_SHA
kubectl apply -f k8s
kubectl set image deployments/client-deployment client=MY_USER/multi-docker-client:$GIT_SHA
kubectl set image deployments/server-deployment server=MY_USER/multi-docker-server:$GIT_SHA
kubectl set image deployments/worker-deployment worker=MY_USER/multi-docker-worker:$GIT_SHA

这是我的项目结构:

enter image description here

最佳答案

原来我只是缺少下一个命令:
gcloud --quiet container clusters get-credentials multi-cluster
作为此任务的一部分:

    # !!! This installs gcloud !!!
    - run:
        name: Installing GCL
        working_directory: /
        command: |
          echo $GCLOUD_SERVICE_KEY | gcloud auth activate-service-account --key-file=-
          gcloud --quiet config set project ${GOOGLE_PROJECT_ID}
          gcloud --quiet config set compute/zone ${GOOGLE_COMPUTE_ZONE}
          gcloud --quiet container clusters get-credentials multi-cluster

向@DazWilkin大喊大叫

关于docker - 部署到gcloud上的CircleCI kubectl配置错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56764361/

相关文章:

docker - Traefik 在 Docker Swarm 中运行的基本配置

java - 如何在 keycloak docker 容器中进行数据库备份

memory-management - 为所有 Pod 全局分配每个 Pod UUID/唯一 ID

python - 由于缺少程序,从 python 运行 bash 脚本失败

docker - 如何以编程方式检查撰写文件中的所有图像是否都在运行?

Docker Compose 如何通过构建扩展服务以使用图像代替

django - Docker/Kubernetes + Gunicorn/Celery - 多个 worker 与副本?

kubernetes - Kubernetes cron作业首先需要一个命令完成吗?

node.js - 从 Node JS App Engine server.js 文件(标准环境)连接到 GCloud SQL 2