Deployment

DSL builds Kubernetes YAML files with a reasonable default structure. Each part of the structure can be customized and overridden.

Basics

.kubes/resources/web/deployment.rb:

name "demo-web"
labels(role: "web")
namespace "default"
replicas 2
image "nginx"

Produces:

.kubes/output/web/deployment.yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: demo-web
  labels:
    app: demo
  namespace: default
spec:
  replicas: 2
  selector:
    matchLabels:
      app: demo
  template:
    metadata:
      labels:
        app: demo
    containers:
    - name: demo-web
      image: nginx

More Customizations

You can override any of the attributes within the deployment structure. You have first-class citizen access to the DSL helpers methods like template and strategy methods that set reasonable defaults.

Examples:

spec(
  replicas: replicas,
  selector: {matchLabels: labels},
  strategy: strategy,
  template: template,
)

If you only have a single container:

container(
  name: name,
  image: "nginx",
  ports: [
    containerPort: 80
  ]
)

For multiple containers:

containers([
  name: name,
  image: "nginx",
  ports: [
    containerPort: 80
  ]
])

Refer to the source code syntax/deployment.rb for more methods available.

DSL Methods

Here’s a list of more common methods:

Top-level and special fields:

  • container
  • containers
  • matchLabels
  • maxSurge
  • maxUnavailable
  • sidecar
  • templateMetadata
  • templateSpec

deployment.spec fields:

  • minReadySeconds
  • progressDeadlineSeconds
  • replicas
  • revisionHistoryLimit
  • selector
  • strategy
  • template

deployment.spec.template.spec.containers fields:

  • args
  • command
  • env
  • envFrom
  • image
  • imagePullPolicy
  • lifecycle
  • livenessProbe
  • containerName
  • ports
  • readinessProbe
  • volumeDevices
  • volumeMounts
  • workingDir

deployment.spec.template.spec.containers.ports fields:

  • containerPort
  • hostIP
  • hostPort
  • portName: Note this field doesn’t match the original field name. It’s more qualified.
  • protocol

For a full list of the available methods, refer to the source itself syntax/deployment.rb.