Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: API Server is needed to deploy #81

Open
richthegeek opened this issue Nov 19, 2018 · 6 comments
Open

Error: API Server is needed to deploy #81

richthegeek opened this issue Nov 19, 2018 · 6 comments

Comments

@richthegeek
Copy link

Im getting this error message and I can't figure out why. As far as I can tell, the API Server is specified in my pipeline:

  deploy_helm:
    image: quay.io/ipedrazas/drone-helm
    api_server: https://my-k8s-server.foo.com
    kubernetes_token: ... token from kube ...
    chart: ./kubernetes/neo
    release: neo
    values: image.tag=${DRONE_BRANCH}-${DRONE_COMMIT_SHA:0:7},version=${DRONE_BRANCH}-${DRONE_COMMIT_SHA:0:7}
    when:
      branch: master
      event: push

Is there anything obviously wrong with that?

Unrelated, but can I use the DNS address as I'm running Drone in the same cluster as the deployment target e.g.: api_server: http://kubernetes.default.svc.local

@robert-bo-davis
Copy link
Contributor

robert-bo-davis commented Nov 19, 2018

API_SERVER and KUBERNETES_TOKEN are configured to be passed in as specifically named environment variables, not as plugin arguments. They should probably be stored in drone as secrets and then passed in like this:

  deploy_helm:
    image: quay.io/ipedrazas/drone-helm
    chart: ./kubernetes/neo
    release: neo
    values: image.tag=${DRONE_BRANCH}-${DRONE_COMMIT_SHA:0:7},version=${DRONE_BRANCH}-${DRONE_COMMIT_SHA:0:7}
    secrets:
      - api_server
      - kubernetes_token
    when:
      branch: master
      event: push

There is an interface in the repository settings UI for managing secrets that isn't described very well in the documentation, but it is fairly simple to use.

@one000mph
Copy link
Contributor

Also worth noting: if you are specifying a prefix that will also apply to your api_server and kubernetes_token secrets. The script I use is

    export ACTION=add
    export REPO=org/myrepo
    export PREFIX=prod_
    # export CLUSTER_URI, UNENCODED_TOKEN, BASE64_CERT
    drone secret $ACTION --repository $REPO --name "${PREFIX}api_server" --value $CLUSTER_URI
    drone secret $ACTION --repository $REPO --name "${PREFIX}kubernetes_token" --value $UNENCODED_TOKEN
    drone secret $ACTION --repository $REPO --name "${PREFIX}kubernetes_certificate" --value $BASE64_CERT```

@captainsano
Copy link

captainsano commented Jan 27, 2019

Am facing the same issue as well, using drone v1.0.5. My step is as follows:

- name: deploy_staging
  image: quay.io/ipedrazas/drone-helm
  settings:
    skip_tls_verify: true
    chart: ./charts/mychart
    release: my-release
    wait: true
    recreate_pods: true
    secrets:
      - api_server
      - kubernetes_token
    values: imageTag=${DRONE_COMMIT_SHA}
    dry_run: true
    debug: true
  when:
    branch: master

I've added the secrets api_server (the cluster ip obtained from kubectl cluster-info) and kubernetes_token by executing docker secret add.... My debug output has the last few lines:

96 | -ReplVar: _API_SERVER => API_SERVER--
97 | -ReplVar: _KUBERNETES_TOKEN => KUBERNETES_TOKEN--
98 | -ReplVar: _SERVICE_ACCOUNT => SERVICE_ACCOUNT--
99 | Error: API Server is needed to deploy.

@one000mph
Copy link
Contributor

Hmm I've had similar issues. Looks like you are not using a prefix at all so it expects the secret to have an underscore _ so your secret should be literally _API_SECRET. Command to add the secret:
drone secret add --repository [repo] --name _API_SECRET --value https://[cluster-ip]

See if that helps? If not, check if that your are setting the permissions on the secret correctly so that all your secrets can be used for the event that you expect. Allowed values are set with the --event flag added to the command above --event push --event tag --event deployment --event pull_request

@ipedrazas
Copy link
Owner

ipedrazas commented Jan 28, 2019 via email

@captainsano
Copy link

captainsano commented Jan 28, 2019

Thanks for your response @one000mph and @ipedrazas! Its working now with the following:

  - name: deploy_staging
    image: quay.io/ipedrazas/drone-helm
    environment:
      STAGING_API_SERVER:
        from_secret: staging_api_server
      STAGING_KUBERNETES_TOKEN:
        from_secret: staging_kubernetes_token
    settings:
         ....

This replaces setting.secrets: [staging_api_server, staging_kubernetes_token] in 0.8 syntax. I added the prefix STAGING, which is also the prefix of the env var.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants