├── .gitignore ├── ANSWERS.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── base-k8s ├── Dockerfile ├── README.md ├── app.py ├── config.yml ├── config │ ├── deployment.yaml │ ├── namespace.yaml │ └── service-base.yaml └── requirements.txt ├── playground1 ├── Dockerfile ├── README.md ├── app.py ├── config │ ├── deployment.yaml │ ├── namespace.yaml │ └── service-broken1.yaml └── requirements.txt ├── playground2 ├── README.md └── config │ ├── deployment.yaml │ ├── namespace.yaml │ └── service.yaml ├── playground3 ├── README.md └── config │ ├── deployment.yaml │ └── namespace.yaml └── playground4 ├── README.md └── config ├── deployment.yaml └── namespace.yaml /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ -------------------------------------------------------------------------------- /ANSWERS.md: -------------------------------------------------------------------------------- 1 | # STOP 2 | # Only read this file AFTER you've tried solving the environments! 3 | 4 | The whole point is to try to solve it yourself first :) 5 | 6 | ## playground1 7 | 8 | Flask is a really, really old version that doesn't work with the syntax. It should also be broken for Python3, which is what the image is based on. 9 | 10 | ## playground2 11 | 12 | There are two problems here. First the deployment specified 0 replicas which means no pods are running. Fix this in config or scale it imperatively with the scale command. Second the pod selector is wrong for the service which means the service has no endpoints. 13 | 14 | ## playground3 15 | 16 | There is a liveness check defined with a bad URL. Use a URL that nginx will respond on. 17 | 18 | ## playground4 19 | 20 | You are missing a secret that the deployment is referencing. Try creating it with `kubectl create secret ...` -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at conduct@nimbinatus.com. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | All constructive contributions are welcome! 4 | 5 | ## Workflow 6 | 7 | Please fork, create a branch, commit your work in atomic elements, and open a PR to contribute. I generally squash and merge or rebase and merge from the PR, so no need to squash it ahead of time if you don't want to. 8 | 9 | ## Environment setup 10 | 11 | Each environment should have its own directory that includes everything you need to start locally unless you cannot demonstrate the common issue with minikube or another local system. Ensure you include a README in each directory with directions on how to start the environment locally. 12 | 13 | ## Naming 14 | 15 | Avoid naming the directory or writing the README in such a way as to give away the problem people are solving for! Also, do not group environments together in sections like _networking_ or _application_. We don't get hints in the real world, so until someone convinces me otherwise, I'd like to keep away from that hinting as much as possible. 16 | 17 | ## Final Notes 18 | 19 | Note that you shouldn't submit fixes to make an environment work properly. That's not the point ;) 20 | 21 | Have fun! 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Laura Santamaria 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # broken-k8s 2 | 3 | A repo full of deliberately broken k8s setups to pull down and practice on. 4 | 5 | ## Who can use this repo? 6 | 7 | Anyone! I was hunting for a set of deliberately broken k8s setups to use to teach debugging strategies for containerization and Kubernetes, but I couldn't find any. So I figured I would create my own. Y'all are welcome to join in! 8 | 9 | ## Answers 10 | 11 | There is an answers file that explains what is wrong with each environment. Don't read it until you've worked toward solving the problem! 12 | 13 | ## Contributing 14 | 15 | Please fork, create a branch, commit your work in atomic elements, and open a PR to contribute. I generally squash and merge or rebase and merge from the PR, so no need to squash it ahead of time if you don't want to. 16 | 17 | Each environment should have its own directory that includes everything you need to start locally. Ensure you include a README in each directory with directions on how to start the environment locally (I've been using minikube). Try to avoid naming the directory or writing the README in such a way as to give away the problem people are solving for! 18 | 19 | Note that you shouldn't submit fixes to make an environment work properly. That's not the point ;) 20 | 21 | Have fun! -------------------------------------------------------------------------------- /base-k8s/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:alpine 2 | RUN python3 -m ensurepip 3 | RUN pip3 install --upgrade pip \ 4 | && pip3 install virtualenv 5 | 6 | RUN adduser -D -g "" -u 1000 starterbase 7 | RUN mkdir -p /base /venv /usr/base 8 | RUN chown -R starterbase:starterbase /base /venv 9 | ENV PYTHONPATH /base 10 | 11 | RUN virtualenv /venv 12 | ENV PATH /venv/bin:${PATH} 13 | 14 | COPY ./requirements.txt /base/requirements.txt 15 | RUN pip3 install -r /base/requirements.txt 16 | COPY . /base 17 | 18 | VOLUME /usr/base 19 | WORKDIR /base 20 | 21 | USER starterbase 22 | 23 | EXPOSE 5000 24 | 25 | CMD ["python3", "-m", "app"] -------------------------------------------------------------------------------- /base-k8s/README.md: -------------------------------------------------------------------------------- 1 | As a note, this one should work, not fail. It's a tester system to ensure that you don't have an error with your system overall. 2 | 3 | ## Local Deployment with Minikube 4 | 5 | First, you'll need to ensure you've got minikube running. 6 | 7 | Set minikube to be able to use local images. 8 | ```bash 9 | $ eval $(minikube docker-env) 10 | ``` 11 | Change directories to the `broken-k8s/base-k8s` directory in your terminal. 12 | 13 | Build the docker image from this directory. 14 | ```bash 15 | $ docker build -t base-k8s . 16 | Sending build context to Docker daemon 9.728kB 17 | Step 1/17 : FROM python:alpine 18 | ... 19 | Successfully tagged base-k8s:latest 20 | ``` 21 | 22 | Create the namespace, service, and deployment. 23 | ```bash 24 | $ kubectl create -f ./config/namespace.yaml 25 | namespace/base-k8s created 26 | $ kubectl create -f ./config/service-base.yaml 27 | service/base-k8s created 28 | $ kubectl create -f ./config/deployment.yaml 29 | deployment.apps/base-k8s created 30 | ``` 31 | 32 | Check that everything is running. 33 | ```bash 34 | $ kubectl get all 35 | NAME READY STATUS RESTARTS AGE 36 | pod/base-k8s-5dc55c4649-5gqs5 1/1 Running 0 3m56s 37 | pod/base-k8s-5dc55c4649-n95xd 1/1 Running 0 3m56s 38 | pod/base-k8s-5dc55c4649-tznls 1/1 Running 0 3m56s 39 | 40 | 41 | NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE 42 | service/base-k8s NodePort 10.97.212.255 5000:31066/TCP 9m28s 43 | 44 | 45 | NAME READY UP-TO-DATE AVAILABLE AGE 46 | deployment.apps/base-k8s 3/3 3 3 3m56s 47 | 48 | NAME DESIRED CURRENT READY AGE 49 | replicaset.apps/base-k8s-5dc55c4649 3 3 3 3m56s 50 | ``` 51 | 52 | Get the local URL to check that you get good output. 53 | ```bash 54 | $ minikube service base-k8s --url -n base-k8s 55 | ``` -------------------------------------------------------------------------------- /base-k8s/app.py: -------------------------------------------------------------------------------- 1 | from flask import Flask 2 | app = Flask(__name__) 3 | 4 | 5 | @app.route('/') 6 | def hello_world(): 7 | return 'hello world' 8 | 9 | 10 | if __name__ == '__main__': 11 | app.run(debug=True, host='0.0.0.0') -------------------------------------------------------------------------------- /base-k8s/config.yml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Pod 3 | metadata: 4 | name: base-k8s 5 | spec: 6 | containers: 7 | - name: flask 8 | image: 9 | -------------------------------------------------------------------------------- /base-k8s/config/deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: base-k8s 5 | namespace: base-k8s 6 | spec: 7 | replicas: 3 8 | selector: 9 | matchLabels: 10 | app: base-k8s 11 | template: 12 | metadata: 13 | labels: 14 | app: base-k8s 15 | spec: 16 | containers: 17 | - name: base-k8s 18 | image: base-k8s:latest 19 | imagePullPolicy: Never 20 | ports: 21 | - containerPort: 5000 -------------------------------------------------------------------------------- /base-k8s/config/namespace.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Namespace 3 | metadata: 4 | name: base-k8s -------------------------------------------------------------------------------- /base-k8s/config/service-base.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: base-k8s 5 | namespace: base-k8s 6 | spec: 7 | selector: 8 | app: base-k8s 9 | ports: 10 | - protocol: TCP 11 | port: 5000 12 | targetPort: 5000 13 | type: NodePort -------------------------------------------------------------------------------- /base-k8s/requirements.txt: -------------------------------------------------------------------------------- 1 | flask -------------------------------------------------------------------------------- /playground1/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:alpine 2 | RUN python3 -m ensurepip 3 | RUN pip3 install --upgrade pip \ 4 | && pip3 install virtualenv 5 | 6 | RUN adduser -D -g "" -u 1000 starterbase 7 | RUN mkdir -p /base /venv /usr/base 8 | RUN chown -R starterbase:starterbase /base /venv 9 | ENV PYTHONPATH /base 10 | 11 | RUN virtualenv /venv 12 | ENV PATH /venv/bin:${PATH} 13 | 14 | COPY ./requirements.txt /base/requirements.txt 15 | RUN pip3 install -r /base/requirements.txt 16 | COPY . /base 17 | 18 | VOLUME /usr/base 19 | WORKDIR /base 20 | 21 | USER starterbase 22 | 23 | EXPOSE 5000 24 | 25 | CMD ["python3", "-m", "app"] -------------------------------------------------------------------------------- /playground1/README.md: -------------------------------------------------------------------------------- 1 | This first playground has a fairly obvious bug if you know where to look! 2 | 3 | 4 | 5 | ## Local Deployment with Minikube 6 | 7 | First, you'll need to ensure you've got minikube running. 8 | 9 | Set minikube to be able to use local images. 10 | ```bash 11 | $ eval $(minikube docker-env) 12 | ``` 13 | Change directories to the `broken-k8s/broken1` directory in your terminal. 14 | 15 | Build the docker image from this directory. 16 | ```bash 17 | $ docker build -t broken1 . 18 | Sending build context to Docker daemon 9.728kB 19 | Step 1/17 : FROM python:alpine 20 | ... 21 | Successfully tagged broken1:latest 22 | ``` 23 | 24 | Create the namespace, service, and deployment. 25 | ```bash 26 | $ kubectl create -f ./config/namespace.yaml 27 | namespace/broken1 created 28 | $ kubectl create -f ./config/service-broken1.yaml 29 | service/broken1 created 30 | $ kubectl create -f ./config/deployment.yaml 31 | deployment.apps/broken1 created 32 | ``` 33 | 34 | Check that everything is "running". 35 | ```bash 36 | $ kubectl get all -n broken1 37 | ``` 38 | 39 | Now go fix it! 40 | -------------------------------------------------------------------------------- /playground1/app.py: -------------------------------------------------------------------------------- 1 | from flask import Flask 2 | app = Flask(__name__) 3 | 4 | 5 | @app.route('/') 6 | def hello_world(): 7 | return 'hello world' 8 | 9 | 10 | if __name__ == '__main__': 11 | app.run(debug=True, host='0.0.0.0') 12 | -------------------------------------------------------------------------------- /playground1/config/deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: broken1 5 | namespace: broken1 6 | spec: 7 | replicas: 3 8 | selector: 9 | matchLabels: 10 | app: broken1 11 | template: 12 | metadata: 13 | labels: 14 | app: broken1 15 | spec: 16 | containers: 17 | - name: broken1 18 | image: broken1:latest 19 | imagePullPolicy: Never 20 | ports: 21 | - containerPort: 5000 -------------------------------------------------------------------------------- /playground1/config/namespace.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Namespace 3 | metadata: 4 | name: broken1 -------------------------------------------------------------------------------- /playground1/config/service-broken1.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: broken1 5 | namespace: broken1 6 | spec: 7 | selector: 8 | app: broken1 9 | ports: 10 | - protocol: TCP 11 | port: 5000 12 | targetPort: 5000 13 | type: NodePort -------------------------------------------------------------------------------- /playground1/requirements.txt: -------------------------------------------------------------------------------- 1 | flask==0.1.0 -------------------------------------------------------------------------------- /playground2/README.md: -------------------------------------------------------------------------------- 1 | This second playground is broken in two ways that you will need to figure out. 2 | 3 | ## Local Deployment with Minikube 4 | 5 | First, you'll need to ensure you've got minikube running. 6 | 7 | Set minikube to be able to use local images. 8 | ```bash 9 | $ eval $(minikube docker-env) 10 | ``` 11 | Change directories to the `broken-k8s/broken2` directory in your terminal. 12 | 13 | Create the namespace, service, and deployment. 14 | ```bash 15 | $ kubectl create -f ./config/namespace.yaml 16 | namespace/broken2 created 17 | $ kubectl create -f ./config/service.yaml 18 | service/broken2 created 19 | $ kubectl create -f ./config/deployment.yaml 20 | deployment.apps/broken2 created 21 | ``` 22 | 23 | Check that everything is "running" and that the service has endpoints. 24 | ```bash 25 | $ kubectl get all -n broken2 26 | $ kubectl get ep -n broken2 27 | ``` 28 | 29 | Things to solve: 30 | * Why aren't your pods running? You can fix it in config, but can you also fix it imperatively? 31 | * Once your pods are running, the service still has no endpoints, what's going on? 32 | -------------------------------------------------------------------------------- /playground2/config/deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: broken2 5 | namespace: broken2 6 | spec: 7 | replicas: 0 8 | selector: 9 | matchLabels: 10 | app: broken2 11 | template: 12 | metadata: 13 | labels: 14 | app: broken2 15 | spec: 16 | containers: 17 | - name: broken2 18 | image: nginx:latest 19 | imagePullPolicy: Always 20 | ports: 21 | - containerPort: 80 22 | -------------------------------------------------------------------------------- /playground2/config/namespace.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Namespace 3 | metadata: 4 | name: broken2 5 | -------------------------------------------------------------------------------- /playground2/config/service.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: broken2 5 | namespace: broken2 6 | spec: 7 | selector: 8 | app: nginx 9 | ports: 10 | - protocol: TCP 11 | port: 80 12 | -------------------------------------------------------------------------------- /playground3/README.md: -------------------------------------------------------------------------------- 1 | The third playground seems healthy, but it's not. Why are pods getting restarted? 2 | 3 | ## Local Deployment with Minikube 4 | 5 | First, you'll need to ensure you've got minikube running. 6 | 7 | Set minikube to be able to use local images. 8 | ```bash 9 | $ eval $(minikube docker-env) 10 | ``` 11 | Change directories to the `broken-k8s/broken3` directory in your terminal. 12 | 13 | Create the namespace, service, and deployment. 14 | ```bash 15 | $ kubectl create -f ./config/namespace.yaml 16 | namespace/broken3 created 17 | $ kubectl create -f ./config/deployment.yaml 18 | deployment.apps/broken3 created 19 | ``` 20 | 21 | Check that everything is "running". 22 | ```bash 23 | $ kubectl get all -n broken3 24 | ``` 25 | 26 | Wait a bit and check again. The pods keep restarting; can you figure out why? 27 | -------------------------------------------------------------------------------- /playground3/config/deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: broken3 5 | namespace: broken3 6 | spec: 7 | replicas: 3 8 | selector: 9 | matchLabels: 10 | app: broken3 11 | template: 12 | metadata: 13 | labels: 14 | app: broken3 15 | spec: 16 | containers: 17 | - name: broken3 18 | image: nginx:latest 19 | imagePullPolicy: Always 20 | readinessProbe: 21 | httpGet: 22 | path: / 23 | port: 80 24 | initialDelaySeconds: 3 25 | periodSeconds: 3 26 | livenessProbe: 27 | httpGet: 28 | path: /healthz 29 | port: 80 30 | initialDelaySeconds: 10 31 | periodSeconds: 3 32 | ports: 33 | - containerPort: 80 34 | -------------------------------------------------------------------------------- /playground3/config/namespace.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Namespace 3 | metadata: 4 | name: broken3 5 | -------------------------------------------------------------------------------- /playground4/README.md: -------------------------------------------------------------------------------- 1 | The fourth playground cannot seem to start any pods. What is missing? 2 | 3 | ## Local Deployment with Minikube 4 | 5 | First, you'll need to ensure you've got minikube running. 6 | 7 | Set minikube to be able to use local images. 8 | ```bash 9 | $ eval $(minikube docker-env) 10 | ``` 11 | Change directories to the `broken-k8s/broken4` directory in your terminal. 12 | 13 | Create the namespace, service, and deployment. 14 | ```bash 15 | $ kubectl create -f ./config/namespace.yaml 16 | namespace/broken4 created 17 | $ kubectl create -f ./config/deployment.yaml 18 | deployment.apps/broken4 created 19 | ``` 20 | 21 | Check that everything is "running". 22 | ```bash 23 | $ kubectl get all -n broken4 24 | ``` 25 | 26 | Why aren't the pods starting? 27 | -------------------------------------------------------------------------------- /playground4/config/deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: broken4 5 | namespace: broken4 6 | spec: 7 | replicas: 3 8 | selector: 9 | matchLabels: 10 | app: broken4 11 | template: 12 | metadata: 13 | labels: 14 | app: broken4 15 | spec: 16 | containers: 17 | - name: broken4 18 | image: nginx:latest 19 | imagePullPolicy: Always 20 | env: 21 | - name: DB_PASSWORD 22 | valueFrom: 23 | secretKeyRef: 24 | name: db-password 25 | key: password 26 | readinessProbe: 27 | httpGet: 28 | path: / 29 | port: 80 30 | initialDelaySeconds: 3 31 | periodSeconds: 3 32 | livenessProbe: 33 | httpGet: 34 | path: / 35 | port: 80 36 | initialDelaySeconds: 10 37 | periodSeconds: 3 38 | ports: 39 | - containerPort: 80 40 | -------------------------------------------------------------------------------- /playground4/config/namespace.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Namespace 3 | metadata: 4 | name: broken4 5 | --------------------------------------------------------------------------------