Sha256: 1824845d750cc2cfdf3023ef27d6609d3cb55701b84abcc64ee0b1f1e44c620b

Contents?: true

Size: 1.42 KB

Versions: 7

Compression:

Stored size: 1.42 KB

Contents

---
title: Auto Context
---

Kubes supports automatically switching the kubectl context based on the `KUBES_ENV`.  Since Kubernetes contexts are composed of three things: cluster, namespace, and user; this feature allows you to target any of them on a per `KUBES_ENV` basis.

## Auto Context

The dev and prod environments can use different kubectl contexts based on what is configured by the Kubes config.rb:

```ruby
Kubes.configure do |config|
  config.kubectl.context = "..."
  # config.kubectl.context_keep = true # keep the context after switching
end
```

You can override configs on a per-env basis with `config/env` files. Examples:

.kubes/config/env/dev.rb

```ruby
Kubes.configure do |config|
  config.repo = "222222222222.dkr.ecr.us-west-2.amazonaws.com/demo"
  config.kubectl.context = "dev-services"
end
```

.kubes/config/env/prod.rb

```ruby
Kubes.configure do |config|
  config.repo = "333333333333.dkr.ecr.us-west-2.amazonaws.com/demo"
  config.kubectl.context = "prod-services"
end
```

## Deploy

With this setup, when you deploy with kubes, it will automatically switch the kubectl context based on `KUBES_ENV`.  Example:

    KUBES_ENV=dev  kubes deploy # to dev-services context
    KUBES_ENV=prod kubes deploy # to prod-services context

## context_keep Option

Setting `context_keep=true` option means after the context it switched, it stays switched. If `context_keep=false`, then Kubes will switch back to the previous context.

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
kubes-0.2.6 docs/_docs/auto-context.md
kubes-0.2.5 docs/_docs/auto-context.md
kubes-0.2.4 docs/_docs/auto-context.md
kubes-0.2.3 docs/_docs/auto-context.md
kubes-0.2.2 docs/_docs/auto-context.md
kubes-0.2.1 docs/_docs/auto-context.md
kubes-0.2.0 docs/_docs/auto-context.md