kube-monkey

by worldtiki

Helm chartv1.11.1App 0.7.1

A Helm chart for Kubernetes

About this chart

Kube-Monkey Helm Chart

Kube-Monkey periodically kills pods in your Kubernetes cluster, that are opt-in based on their own rules.

Add repository

helm repo add kubemonkey https://asobti.github.io/kube-monkey/charts/repo
helm repo update

Installing the Chart

To install the chart with the release name my-release:

helm install my-release kubemonkey/kube-monkey --version 1.11.1

The command deploys kube-monkey on the Kubernetes cluster in the default configuration. The configurations section lists the parameters that can be configured during installation.

Uninstalling the Chart

To uninstall/delete the my-release deployment:

$ helm delete my-release

The command removes all the Kubernetes components associated with the chart and deletes the release.

Customising Configurations

By default Kube-Monkey runs in dry-run mode so it doesn't actually kill anything. If you're confident you want to use it in real run helm with:

$ helm install my-release kubemonkey --set config.dryRun=false

By default Kube-Monkey runs in without any white listed namespace assigned so it doesn't actually kill anything. If you're confident you want to enable it in real, run helm with:

$ helm install my-release kubemonkey \
               --set config.dryRun=false \
               --set config.whitelistedNamespaces="{namespace1,namespace2,namespace3}"

Note: replace namespace with your real namespaces

If you want to see how kube-monkey kills pods immediately in debug mode.

$ helm install my-release kubemonkey \
               --set config.dryRun=false \
               --set config.whitelistedNamespaces="{namespace1,namespace2,namespace3}"
               --set config.debug.enabled=true \
               --set config.debug.schedule_immediate_kill=true

If you want to change the time kube-monkey wakes up and start and end killing pods.

$ helm install my-release kubemonkey \
               --set config.dryRun=false \
               --set config.whitelistedNamespaces="{namespace1,namespace2,namespace3}"
               --set config.runDays="{mon,wed,fri}" \
               --set config.runHour=10 \
               --set config.startHour=11 \
               --set config.endHour=17 

If you want to enable attacks notifications.

$ helm install my-release kubemonkey \
               --set config.dryRun=false \
               --set config.whitelistedNamespaces="namespace1\"\,\"namespace2\"\,\"namespace3" \
               --set config.notifications.enabled=true \
               --set config.notifications.endpoint=http://localhost:8080/path \
               --set config.notifications.message="{\"foo\":\"bar\"}" \
               --set config.notifications.headers="Content-Type:application/json\"\,\"client-id:kubemonkey"

If you want to serve Prometheus metrics and have the Prometheus Operator scrape them.

$ helm install my-release kubemonkey \
               --set config.metrics.enabled=true \
               --set serviceMonitor.enabled=true

If you want validate intended values passed in to configmap .

$ helm get manifest my-release

Configurations

ParameterDescriptionDefault
image.repositorydocker image repoayushsobti/kube-monkey
image.tagdocker image tagv0.7.1
replicaCountnumber of replicas to run1
image.pullPolicyimage pull logicIfNotPresent
config.dryRunwill not kill pods, only logs behaviourtrue
config.runHourschedule start time in 24hr format8
config.startHourpod killing start time in 24hr format10
config.endHourpod killing stop time in 24hr format16
config.whitelistedNamespacespods in this namespace that opt-in will be killed
config.blacklistedNamespacespods in this namespace will not be killedkube-system
config.timeZonetime zone in DZ formatAmerica/New_York
config.debug.enableddebug mode,need to be enabled to see debuging behaviourfalse
config.debug.schedule_delayseconds to wait before each scheduling run30
config.debug.force_should_killschedule a termination for every eligible appfalse
config.debug.schedule_immediate_killimmediate pod kill matching other rules apart from timefalse
config.notifications.enabledenables reporting of attacks to an HTTP endpointfalse
config.notifications.proxynotifications proxy URL
config.notifications.attacksHTTP collector in the form (endpoint,message,headers) where attacks will be reported to
config.metrics.enabledserves Prometheus metrics on /metrics and creates a Service for themfalse
config.metrics.portport the metrics endpoint listens on8080
serviceMonitor.enabledcreates a ServiceMonitor for the Prometheus Operator, needs config.metrics.enabledfalse
serviceMonitor.intervalhow often Prometheus scrapes the metrics30s
serviceMonitor.scrapeTimeouthow long Prometheus waits for a scrape10s
serviceMonitor.additionalLabelsextra labels on the ServiceMonitor, to match your Prometheus selector{}
args.logLevelgo log level5
args.logDirwrites log files to this directory, empty means stderr only
args.extraArgsextra command line flags for kube-monkey[]
additionalVolumesextra volumes on the pod[]
additionalVolumeMountsextra volume mounts on the container[]
podSecurityContextsecurity context for the pod{}

after all you can simply edit values.yaml with your preferred configs and run as below

$ helm install my-release kubemonkey --namespace=kube-monkey

example of a modified values.yaml (only important parts are displayed)

...
replicaCount: 1
image:
  repository: ayushsobti/kube-monkey
  tag: v0.7.1
  pullPolicy: IfNotPresent
config:
  dryRun: false
  runHour: 8
  startHour: 10
  endHour: 16
  blacklistedNamespaces: [ "kube-system" ]
  whitelistedNamespaces: [ "namespace1", "namespace2" ]
  timeZone: America/New_York
args:
  logLevel: 5
...

Logging

By default kube-monkey logs to the container's stderr only, so kubectl logs shows everything and nothing is written to disk.

Set args.logDir if you also want glog log files. The image runs on an empty filesystem, so you have to mount a writable volume at that same path:

args:
  logLevel: 5
  logDir: /var/log/kube-monkey

additionalVolumes:
  - name: log
    emptyDir: {}

additionalVolumeMounts:
  - name: log
    mountPath: /var/log/kube-monkey

Running as a non-root user

Nothing beyond podSecurityContext is needed while logs go to stderr:

podSecurityContext:
  runAsNonRoot: true
  runAsUser: 1001
  runAsGroup: 1001
  fsGroup: 1001

If you also set args.logDir, add the volume shown above. Without it the user cannot create the directory and kube-monkey will not start.

Deploy kube-monkey with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has kube-monkey on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartkube-monkey is pinned at v1.11.1 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply