Skip to content

Commit

Permalink
feat(k8s): add kubernetes module type
Browse files Browse the repository at this point in the history
For those times when you want to deploy your own manifests, but don't
need the features and complexity of Helm modules.

See the kubernetes-module example for usage.
  • Loading branch information
edvald authored and thsig committed Mar 28, 2019
1 parent cd96adf commit 1488cd8
Show file tree
Hide file tree
Showing 10 changed files with 949 additions and 0 deletions.
148 changes: 148 additions & 0 deletions docs/reference/module-types/kubernetes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
# `kubernetes` reference

Below is the schema reference for the `kubernetes` module type. For an introduction to configuring Garden modules, please look at our [Configuration guide](../../using-garden/configuration-files.md).

The reference is divided into two sections. The [first section](#configuration-keys) lists and describes the available schema keys. The [second section](#complete-yaml-schema) contains the complete YAML schema.

## Configuration keys

### `module`



| Type | Required |
| ---- | -------- |
| `object` | No
### `module.build`
[module](#module) > build

Specify how to build the module. Note that plugins may define additional keys on this object.

| Type | Required |
| ---- | -------- |
| `object` | No
### `module.build.dependencies[]`
[module](#module) > [build](#module.build) > dependencies

A list of modules that must be built before this module is built.

| Type | Required |
| ---- | -------- |
| `array[object]` | No

Example:
```yaml
module:
...
build:
...
dependencies:
- name: some-other-module-name
```
### `module.build.dependencies[].name`
[module](#module) > [build](#module.build) > [dependencies](#module.build.dependencies[]) > name

Module name to build ahead of this module.

| Type | Required |
| ---- | -------- |
| `string` | Yes
### `module.build.dependencies[].copy[]`
[module](#module) > [build](#module.build) > [dependencies](#module.build.dependencies[]) > copy

Specify one or more files or directories to copy from the built dependency to this module.

| Type | Required |
| ---- | -------- |
| `array[object]` | No
### `module.build.dependencies[].copy[].source`
[module](#module) > [build](#module.build) > [dependencies](#module.build.dependencies[]) > [copy](#module.build.dependencies[].copy[]) > source

POSIX-style path or filename of the directory or file(s) to copy to the target.

| Type | Required |
| ---- | -------- |
| `string` | Yes
### `module.build.dependencies[].copy[].target`
[module](#module) > [build](#module.build) > [dependencies](#module.build.dependencies[]) > [copy](#module.build.dependencies[].copy[]) > target

POSIX-style path or filename to copy the directory or file(s) to (defaults to same as source path).

| Type | Required |
| ---- | -------- |
| `string` | No
### `module.dependencies[]`
[module](#module) > dependencies

List of names of services that should be deployed before this chart.

| Type | Required |
| ---- | -------- |
| `array[string]` | No
### `module.manifests[]`
[module](#module) > manifests

List of Kubernetes resource manifests to deploy. Use this instead of the `files` field if you need to resolve template strings in any of the manifests.

| Type | Required |
| ---- | -------- |
| `array[object]` | No
### `module.manifests[].apiVersion`
[module](#module) > [manifests](#module.manifests[]) > apiVersion

The API version of the resource.

| Type | Required |
| ---- | -------- |
| `string` | Yes
### `module.manifests[].kind`
[module](#module) > [manifests](#module.manifests[]) > kind

The kind of the resource.

| Type | Required |
| ---- | -------- |
| `string` | Yes
### `module.manifests[].metadata`
[module](#module) > [manifests](#module.manifests[]) > metadata



| Type | Required |
| ---- | -------- |
| `object` | Yes
### `module.manifests[].metadata.name`
[module](#module) > [manifests](#module.manifests[]) > [metadata](#module.manifests[].metadata) > name

The name of the resource.

| Type | Required |
| ---- | -------- |
| `string` | Yes
### `module.files[]`
[module](#module) > files

POSIX-style paths to YAML files to load manifests from. Each can contain multiple manifests.

| Type | Required |
| ---- | -------- |
| `array[string]` | No


## Complete YAML schema
```yaml
module:
build:
dependencies:
- name:
copy:
- source:
target: ''
dependencies: []
manifests:
- apiVersion:
kind:
metadata:
name:
files: []
```
17 changes: 17 additions & 0 deletions examples/kubernetes-module/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# `kubernetes` module type example

This is a simple example demonstrating the `kubernetes` module type.
The `kubernetes` module type is useful when you want to deploy your own manifests to Kubernetes, but don't need the
features (and complexity) of `helm` modules.

This example contains a `redis` module and a `postgres` module. Both contain manifests that are, for the purposes of
this example, rendered from their respective official Helm charts (by running the `helm template` command).

The `redis` module has its manifests in a separate YAML file, whereas the `postgres` module has the manifests inlined
in the `garden.yml` file, which allows us to use template strings to set variable values.
We set the Postgres instance password through a variable in the project `garden.yml` to demonstrate that capability.

To give it a spin, just run `garden deploy` in the module directory.

To see that the Postgres password was correctly set, run `kubectl -n kubernetes-module get secret postgres -o yaml`
and check that the password matches the one in the project `garden.yml` file.
8 changes: 8 additions & 0 deletions examples/kubernetes-module/garden.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
kind: Project
name: kubernetes-module
environments:
- name: local
providers:
- name: local-kubernetes
variables:
postgres-password: "Y0RGQjBHUmpWZQ=="
168 changes: 168 additions & 0 deletions examples/kubernetes-module/postgres/garden.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
kind: Module
type: kubernetes
name: postgres
description: Postgres deployment with kubernetes manifests inlined (extracted from the stable/postgresql Helm chart)
manifests:
# Source: postgresql/templates/secrets.yaml
- apiVersion: v1
kind: Secret
metadata:
name: postgres
labels:
app: postgresql
chart: postgresql-3.9.2
release: "postgres"
heritage: "Tiller"
type: Opaque
data:
postgresql-password: ${variables.postgres-password}
# Source: postgresql/templates/svc-headless.yaml
- apiVersion: v1
kind: Service
metadata:
name: postgres-headless
labels:
app: postgresql
chart: postgresql-3.9.2
release: "postgres"
heritage: "Tiller"
spec:
type: ClusterIP
clusterIP: None
ports:
- name: postgresql
port: 5432
targetPort: postgresql
selector:
app: postgresql
release: "postgres"
# Source: postgresql/templates/svc.yaml
- apiVersion: v1
kind: Service
metadata:
name: postgres
labels:
app: postgresql
chart: postgresql-3.9.2
release: "postgres"
heritage: "Tiller"
spec:
type: ClusterIP
ports:
- name: postgresql
port: 5432
targetPort: postgresql
selector:
app: postgresql
release: "postgres"
role: master
- # Source: postgresql/templates/statefulset.yaml
apiVersion: apps/v1beta2
kind: StatefulSet
metadata:
name: postgres
labels:
app: postgresql
chart: postgresql-3.9.2
release: "postgres"
heritage: "Tiller"
spec:
serviceName: postgres-headless
replicas: 1
updateStrategy:
type: RollingUpdate
selector:
matchLabels:
app: postgresql
release: "postgres"
role: master
template:
metadata:
name: postgres
labels:
app: postgresql
chart: postgresql-3.9.2
release: "postgres"
heritage: "Tiller"
role: master
spec:
securityContext:
fsGroup: 1001
runAsUser: 1001
initContainers:
- name: init-chmod-data
image: docker.io/bitnami/minideb:latest
imagePullPolicy: "Always"
resources:
requests:
cpu: 250m
memory: 256Mi

command:
- sh
- -c
- |
chown -R 1001:1001 /bitnami
if [ -d /bitnami/postgresql/data ]; then
chmod 0700 /bitnami/postgresql/data;
fi
securityContext:
runAsUser: 0
volumeMounts:
- name: data
mountPath: /bitnami/postgresql
containers:
- name: postgres
image: docker.io/bitnami/postgresql:10.6.0
imagePullPolicy: "Always"
resources:
requests:
cpu: 250m
memory: 256Mi

env:
- name: POSTGRESQL_USERNAME
value: "postgres"
- name: POSTGRESQL_PASSWORD
valueFrom:
secretKeyRef:
name: postgres
key: postgresql-password
ports:
- name: postgresql
containerPort: 5432
livenessProbe:
exec:
command:
- sh
- -c
- exec pg_isready -U "postgres" -h localhost
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
successThreshold: 1
failureThreshold: 6
readinessProbe:
exec:
command:
- sh
- -c
- exec pg_isready -U "postgres" -h localhost
initialDelaySeconds: 5
periodSeconds: 10
timeoutSeconds: 5
successThreshold: 1
failureThreshold: 6
volumeMounts:
- name: data
mountPath: /bitnami/postgresql
volumes:
volumeClaimTemplates:
- metadata:
name: data
spec:
accessModes:
- "ReadWriteOnce"
resources:
requests:
storage: "8Gi"
5 changes: 5 additions & 0 deletions examples/kubernetes-module/redis/garden.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: Module
type: kubernetes
name: redis
description: Redis deployment with kubernetes manifests in a file ((extracted from the stable/redis Helm chart))
files: [redis.yml]
Loading

0 comments on commit 1488cd8

Please sign in to comment.