chaos monkey

This commit is contained in:
Lucian Suciu
2019-03-25 11:30:37 +02:00
parent 1a432e45e6
commit 93516a8a2c
12 changed files with 146 additions and 3 deletions

Submodule e2e-test/qa/chaos/kubernetes-pod-chaos-monkey deleted from f3e1cc7c1d

View File

@@ -0,0 +1,11 @@
FROM debian:jessie
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -y install \
curl
ARG KUBECTL_URL=https://storage.googleapis.com/kubernetes-release/release/v1.13.0/bin/linux/amd64/kubectl
RUN cd /usr/local/bin && curl -O $KUBECTL_URL && chmod 755 kubectl
WORKDIR /usr/src/app
COPY chaos.sh ./
CMD ["bash", "/usr/src/app/chaos.sh"]

View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2016 Jesse Newland
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1,39 @@
# Kubernetes Pod Chaos Monkey
This repository contains a `Dockerfile` and associated Kubernetes configuration for a Deployment that will randomly delete pods in a given namespace. This is implemented in Bash mostly because I'm writing it for a lightning talk.
An image built from the `Dockerfile` in this repository is available on Docker Hub as [`jnewland/kubernetes-pod-chaos-monkey`](https://hub.docker.com/r/jnewland/kubernetes-pod-chaos-monkey/).
### Configuration
A few environment variables are available for configuration:
* `DELAY`: seconds between selecting and deleting a pod. Defaults to `30`.
* `NAMESPACE`: the namespace to select a pod from. Defaults to `default`.
Example Kubernetes config is included at [`config/kubernetes/production/deployment.yaml`](./config/kubernetes/production/deployment.yaml)
### Example
```bash
$ kubectl apply -f config/kubernetes/production/deployment.yaml
deployment "kubernetes-pod-chaos-monkey" created
$ kubectl get pods | grep chaos
kubernetes-pod-chaos-monkey-3294408070-6w6oh 1/1 Running 0 19s
$ kubectl logs kubernetes-pod-chaos-monkey-3294408070-6w6oh
+ : 30
+ : default
+ true
+ xargs -t --no-run-if-empty kubectl --namespace default delete pod
+ head -n 1
+ shuf
+ tr ' ' '\n'
+ kubectl --namespace default -o 'jsonpath={.items[*].metadata.name}' get pods
kubectl --namespace default delete pod dd-agent-3hw6w
pod "dd-agent-3hw6w" deleted
+ sleep 30
```
## License
[MIT](./LICENSE.md)

View File

@@ -0,0 +1,17 @@
#!/bin/bash
# Randomly delete pods in a Kubernetes namespace.
set -ex
while true
do
kubectl \
--namespace "${NAMESPACE}" \
-o 'jsonpath={.items[*].metadata.name}' \
get pods | \
tr " " "\n" | \
shuf | \
head -n ${KILL_NR} |
xargs -t --no-run-if-empty \
kubectl --namespace "${NAMESPACE}" delete pod
sleep "${DELAY_SEC}"
done

View File

@@ -0,0 +1,18 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: kubernetes-pod-chaos-monkey
spec:
selector:
matchLabels:
app: kubernetes-pod-chaos-monkey
replicas: 1
template:
metadata:
labels:
app: kubernetes-pod-chaos-monkey
spec:
containers:
- name: kubernetes-pod-chaos-monkey
image: jnewland/kubernetes-pod-chaos-monkey
imagePullPolicy: Always

View File

@@ -5,4 +5,5 @@ metadata:
type: kubernetes.io/dockerconfigjson
data:
# Docker registries config json in base64 to do this just run - cat ~/.docker/config.json | base64
.dockerconfigjson: ewoJImF1dGhzIjogewoJCSJkb2NrZXItaW50ZXJuYWwuYWxmcmVzY28uY29tIjogewoJCQkiYXV0aCI6ICJiSE4xWTJsMU9rbHVaV1poWW1sc01USWpKQT09IgoJCX0sCgkJImh0dHBzOi8vZG9ja2VyLWludGVybmFsLmFsZnJlc2NvLmNvbSI6IHsKCQkJImF1dGgiOiAiYkhOMVkybDFPa2x1WldaaFltbHNNVElqSkE9PSIKCQl9LAoJCSJodHRwczovL2luZGV4LmRvY2tlci5pby92MS8iOiB7CgkJCSJhdXRoIjogImJtVnpjM0p2T2tGdFltbGxiblJoYkRFd01BPT0iCgkJfSwKCQkiaHR0cHM6Ly9xdWF5LmlvIjogewoJCQkiYXV0aCI6ICJiSE4xWTJsMU9tRnBkWEpsWVRFeU13PT0iCgkJfSwKCQkicXVheS5pbyI6IHsKCQkJImF1dGgiOiAiYkhOMVkybDFPbUZwZFhKbFlURXlNdz09IgoJCX0KCX0sCgkiSHR0cEhlYWRlcnMiOiB7CgkJIlVzZXItQWdlbnQiOiAiRG9ja2VyLUNsaWVudC8xNy4xMi4wLWNlIChkYXJ3aW4pIgoJfQp9
# REMEMBER TO ADD A WORKING USER FOR THIS
.dockerconfigjson: ewoJImF1dGhzIjogewoCSJkb2NrZXItaW50ZXJuYWwuYWxmcmVzY28uY29tIjogewoJCQkiYXV0aCI6ICJiSE4xWTJsMU9rbHVaV1poWW1sc01USWpKQT09IgoJCX0sCgkJImh0dHBzOi8vZG9ja2VyLWludGVybmFsLmFsZnJlc2NvLmNvbSI6IHsKCQkJImF1dGgiOiAiYkhOMVkybDFPa2x1WldaaFltbHNNVElqSkE9PSIKCQl9LAoJCSJodHRwczovL2luZGV4LmRvY2tlci5pby92MS8iOiB7CgkJCSJhdXRoIjogImJtVnpjM0p2T2tGdFltbGxiblJoYkRFd01BPT0iCgkJfSwKCQkiaHR0cHM6Ly9xdWF5LmlvIjogewoJCQkiYXV0aCI6ICJiSE4xWTJsMU9tRnBkWEpsWVRFeU13PT0iCgkJfSwKCQkicXVheS5pbyI6IHsKCQkJImF1dGgiOiAiYkhOMVkybDFPbUZwZFhKbFlURXlNdz09IgoJCX0KCX0sCgkiSHR0cEhlYWRlcnMiOiB7CgkJIlVzZXItQWdlbnQiOiAiRG9ja2VyLUNsaWVudC8xNy4xMi4wLWNlIChkYXJ3aW4pIgoJfQp9

Submodule e2e-test/qa/chaos/stupid-server deleted from 3eb18bc7ca

View File

@@ -0,0 +1,13 @@
# DOCKER-VERSION 0.11.0
FROM quay.io/seanmcgary/nodejs-raw-base
MAINTAINER Sean McGary <sean@seanmcgary.com>
EXPOSE 8000
ADD start.sh start.sh
RUN chmod +x start.sh
CMD ./start.sh

View File

@@ -0,0 +1,7 @@
var http = require('http');
var server = http.createServer(function(req, res){
res.end(new Date().toISOString());
});
server.listen(8000);

View File

@@ -0,0 +1,4 @@
git clone https://github.com/seanmcgary/stupid-server.git stupid-server
node stupid-server

View File

@@ -0,0 +1,14 @@
[Unit]
Description=Stupid Server
After=docker.service
Requires=docker.service
[Service]
User=core
ExecStartPre=/bin/bash -c '/usr/bin/docker run --rm -v /opt/bin:/opt/bin ibuildthecloud/systemd-docker && /usr/bin/docker pull quay.io/seanmcgary/stupid-server'
ExecStart=/bin/bash -c '/opt/bin/systemd-docker run --name stupidservice -p 9000:8000 quay.io/seanmcgary/stupid-server'
TimeoutStartSec=0
Restart=always
RestartSec=10s
Type=notify
NotifyAccess=all