Skip to content

Shorter deploy commands #301

Description

@ramontayag

Feature request

  • If the maintainers agree with the feature as described here, I intend to submit a Pull Request myself.1

Proposal: provide shorter deploy commands

Currently, a deploy command looks like:

KUBECONFIG=~/.kube/config ENVIRONMENT=staging REVISION=958567c80b1d288255e77df0fa9bd381dec784ab kubernetes-deploy mynamespace gke_company-project-name_us-central1-a_anothername

This is quite long. There are certain things that probably don't change between deploys. These things can be potentially removed using direnv or similar tools, but there are other things that differ from deploy to deploy.

I propose a command reminiscent of the Capistrano command:

# deploy the latest revision of master branch to a set default (most likely production):
kubernetes-deploy master

# deploy the latest revision of staging_06 branch to a set default (most likely staging)
kubernetes-deploy staging_06

# deploy the latest revision of master branch to staging (override the default)
kubernetes-deploy master staging

# deploy revision 958567c80b1d288255e77df0fa9bd381dec784ab to staging
kubernetes-deploy 958567c80b1d288255e77df0fa9bd381dec784ab staging

# yes, you can override others too
kubernetes-deploy master staging

Below you'll find ways I think we can achieve this, parameter at a time.

KUBECONFIG

This will likely never change per machine, but may be different machine to machine. A solution to this would be to use direnv or a similar format where we have a .envrc.local that is listed in .gitignore that either a) exports the environment variable export KUBECONFIG=/path/to/kubeconfig/on/my/machine. If .envrc.local does not exist, then kubernetes-deploy can require KUBECONFIG to bet set like it is today.

ENVIRONMENT

When running kubernetes-deploy master staging, it's obvious what ENVIRONMENT will be. However, it should have a default depending on the branch that is being deployed.

In config/deploy/config.yml, something like this can be specified:

deploys:
  - branch: master
    environment: production
  - branch: /staging_(\d+)/
    environment: staging

We would need to recognize regex

kubernetes-deploy would be smart enough to figure out that if a branch name is being passed in and no environment is specified, it will default to what is listed in the config.yml. If that file does not exist, then yes it will have to require ENVIRONMENT or the second argument in kubernetes-deploy master staging.

This config is something that will be committed to the project, and will be the same for all developers. If the developer need to customize this, then the setting either does not belong to the config file or there should be a way to override it.

Namespace

There are two solutions I've thought of that would eliminate the need to specify the namespace each deploy:

  1. Templates found in config/#{environment}/* can specify the namespace (this isn't the case today though, perhaps because of template reuse?)
  2. Add it to the config:
deploys:
  - branch: master
    environment: production
    namespace: prod
  - branch: /staging_(\d+)/
    environment: staging
    namespace: stg

Cluster name

The cluster name may be the differ between environments, but I could not think of a reason it would differ per developer. Therefore, I think this can be saved in the config as well:

deploys:
  - branch: master
    environment: production
    namespace: default
    context: gke_company-project-name_us-central1-prod
  - branch: /staging_(\d+)/
    environment: staging
    namespace: default
    context: gke_company-project-name_us-central1-stg

Closing

There should be a way to still keep the old format and the new format working. If you'd rather not overload kubernetes-deploy that's perfectly understandable. This can be in another command like kdeploy, which underneath calls kubernetes-deploy. In fact, maybe this can be done in a separate gem that uses kubernetes-deploy underneath (what do you think?). 🤔

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    🆕 featureMakes something new possible

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions