0.1.0 • Published 5 years ago

rancher-2-deploy v0.1.0

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

Rancher 2.x Deploy Tool

Deployment tool for updating workloads on Rancher 2.x managed cluster with v3 API. It was developed for gitlab CD pipeline, but can be used for any other workflow. Influenced by the project rancher-gitlab-deploy.

It can be used as CLI tool, Node.js module or CI/CD pipeline tool as a docker image. It can be easily integrated into gitlab-ci.yml or .rancher-pipeline.yml using environment variables.

Right now it's only possible to redeploy a workload, so first you'll need to deploy your workload manually.

Usage

First you need to get an API key from your Rancher Cluster. In Rancher go to User Avatar > API & Keys > Add Key (more info).

Gitlab CI/CD Pipeline

Save the key as an environment variable in your GitLab project. On the GitLab project page go to Settings > CI / CD > Variables (more info).

RANCHER_ENDPOINT - https://rancher.example.com/v3

RANCHER_ACCESS_KEY - token-12345

RANCHER_SECRET_KEY - 0123456789abcdefghijklmnopqrstuvwxyz

Deploy your project on Rancher GUI under Default project to default namespace, then put a deploy stage to your gitlab-ci.yml:

deploy:
  stage: deploy
  image: registry.gitlab.com/heyj0e/rancher-2-deploy
  script:
    - deploy --workload <workload-name>

If you want to specify the project and/or the namespace:

deploy:
  stage: deploy
  image: registry.gitlab.com/heyj0e/rancher-2-deploy
  script:
    - deploy --project <project-name> --namespace <namespace-name> --workload <workload-name>

Node.js module

Install it using npm:

npm install rancher-2-deploy --save

Use:

const rancherRedeploy = require('rancher-2-deploy');

const options = {
  endpoint: 'https://myserver.com/v3',
  accessKey: 'token-12345',
  secretKey: '0123456789abcdefghijklmnopqrstuvwxyz',
  project: 'My Rancher Project', // if omitted, Default will be used
  namespace: 'My Namespace', // if omitted, default will be used
  workload: 'my-awesome-workload',
};

rancherRedeploy(options);
// returns Promise, then Rancher's answer

Authors

  • Joseph Ivan - Initial work - HeyJ0e

License

This project is licensed under the MIT License - see the LICENSE file for details