├── .gitignore ├── 01-ImagePullBackOff ├── 01-invalid-image.md ├── 02-private-image.md └── README.md ├── 02-CrashLoopBackOff ├── 01-wrong-cmd-crashloop.yml ├── 02-livenessprobe-crashloop.yml ├── 03-out-of-memory-crashloop.yml ├── README.md └── simple-python-app │ ├── .dockerignore │ ├── Dockerfile │ ├── README.Docker.md │ ├── app.py │ ├── compose.yaml │ └── requirements.txt ├── 03-pods-not-schedulable ├── 01-kind-cluster.yaml ├── 02-node-selector.yaml ├── 03-node-affinity-preferred.yaml ├── 04-node-affinity-required.yaml └── README.md ├── 04-statefulset-pv └── sample-statefulset.yaml ├── 05-networkpolicy ├── db.yaml ├── hack.yaml └── network-policy.yaml ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # If you prefer the allow list template instead of the deny list, see community template: 2 | # https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore 3 | # 4 | # Binaries for programs and plugins 5 | *.exe 6 | *.exe~ 7 | *.dll 8 | *.so 9 | *.dylib 10 | 11 | # Test binary, built with `go test -c` 12 | *.test 13 | 14 | # Output of the go coverage tool, specifically when used with LiteIDE 15 | *.out 16 | 17 | # Dependency directories (remove the comment below to include it) 18 | # vendor/ 19 | 20 | # Go workspace file 21 | go.work 22 | -------------------------------------------------------------------------------- /01-ImagePullBackOff/01-invalid-image.md: -------------------------------------------------------------------------------- 1 | # Invalid Image 2 | 3 | `ImagePullBackoff` can be caused if the pod runs with an invalid image or typo in the image name or even a non-existent image. 4 | 5 | Watch the demo on the youtube channel for practical understanding. -------------------------------------------------------------------------------- /01-ImagePullBackOff/02-private-image.md: -------------------------------------------------------------------------------- 1 | # Private Image 2 | 3 | We will learn how to create a Pod that uses a Secret to pull an image from a private container image registry or repository. 4 | 5 | ### Create a Secret by providing Docker credentials on the command line 6 | 7 | ``` 8 | kubectl create secret docker-registry demo --docker-server= --docker-username= --docker-password= --docker-email= 9 | ``` 10 | 11 | ### Create a Secret by providing AWS ECR credentials on the command line 12 | 13 | ``` 14 | kubectl create secret docker-registry \ 15 | --docker-server=${AWS_ACCOUNT}.dkr.ecr.${AWS_REGION}.amazonaws.com \ 16 | --docker-username=AWS \ 17 | --docker-password=$(aws ecr get-login-password) \ 18 | --namespace=default 19 | ``` -------------------------------------------------------------------------------- /01-ImagePullBackOff/README.md: -------------------------------------------------------------------------------- 1 | # ImagePullBackoff 2 | 3 | When a kubelet starts creating containers for a Pod using a container runtime, it might be possible the container is in Waiting state because of ImagePullBackOff. 4 | 5 | The status ImagePullBackOff means that a container could not start because Kubernetes could not pull a container image for reasons such as 6 | 7 | - Invalid image name or 8 | - Pulling from a private registry without imagePullSecret. 9 | 10 | The BackOff part indicates that Kubernetes will keep trying to pull the image, with an increasing back-off delay. 11 | 12 | Kubernetes raises the delay between each attempt until it reaches a compiled-in limit, which is 300 seconds (5 minutes). -------------------------------------------------------------------------------- /02-CrashLoopBackOff/01-wrong-cmd-crashloop.yml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: crashloop-example 5 | labels: 6 | app: crashlooplearning 7 | spec: 8 | replicas: 1 9 | selector: 10 | matchLabels: 11 | app: crashlooplearning 12 | template: 13 | metadata: 14 | labels: 15 | app: crashlooplearning 16 | spec: 17 | containers: 18 | - name: crashlooplearning 19 | image: abhishekf5/crashlooptest:v1 20 | ports: 21 | - containerPort: 8000 22 | -------------------------------------------------------------------------------- /02-CrashLoopBackOff/02-livenessprobe-crashloop.yml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: crashloop-example 5 | labels: 6 | app: crashlooplearning 7 | spec: 8 | replicas: 1 9 | selector: 10 | matchLabels: 11 | app: crashlooplearning 12 | template: 13 | metadata: 14 | labels: 15 | app: crashlooplearning 16 | spec: 17 | containers: 18 | - name: crashlooplearning 19 | image: abhishekf5/crashlooptest:v2 20 | ports: 21 | - containerPort: 8000 22 | livenessProbe: 23 | exec: 24 | command: 25 | - cat 26 | - /tmp/healthy 27 | initialDelaySeconds: 0 28 | periodSeconds: 1 29 | -------------------------------------------------------------------------------- /02-CrashLoopBackOff/03-out-of-memory-crashloop.yml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: crashloop-example 5 | labels: 6 | app: crashlooplearning 7 | spec: 8 | replicas: 1 9 | selector: 10 | matchLabels: 11 | app: crashlooplearning 12 | template: 13 | metadata: 14 | labels: 15 | app: crashlooplearning 16 | spec: 17 | containers: 18 | - name: crashlooplearning 19 | image: abhishekf5/crashlooptest:v2 20 | ports: 21 | - containerPort: 8000 22 | resources: 23 | limits: 24 | cpu: "25m" 25 | memory: "25Mi" 26 | 27 | -------------------------------------------------------------------------------- /02-CrashLoopBackOff/README.md: -------------------------------------------------------------------------------- 1 | # CrashLoopBackOff 2 | 3 | When you see "CrashLoopBackOff," it means that kubelet is trying to run the container, but it keeps failing and crashing. After crashing, Kubernetes tries to restart the container automatically, but if the container keeps failing repeatedly, you end up in a loop of crashes and restarts, thus the term "CrashLoopBackOff." 4 | 5 | This situation indicates that something is wrong with the application or the configuration that needs to be fixed. 6 | 7 | ## Common Situations of CrashLoopBackOff 8 | 9 | The CrashLoopBackOff error in Kubernetes indicates that a container is repeatedly crashing and restarting. Here are explanations of how the CrashLoopBackOff error can occur due to the specific reasons you listed: 10 | 11 | ### Misconfigurations 12 | 13 | Misconfigurations can encompass a wide range of issues, from incorrect environment variables to improper setup of service ports or volumes. These misconfigurations can prevent the application from starting correctly, leading to crashes. For example, if an application expects a certain environment variable to connect to a database and that variable is not set or is incorrect, the application might crash as it cannot establish a database connection. 14 | 15 | ### Errors in the Liveness Probes 16 | 17 | Liveness probes in Kubernetes are used to check the health of a container. If a liveness probe is incorrectly configured, it might falsely report that the container is unhealthy, causing Kubernetes to kill and restart the container repeatedly. For example, if the liveness probe checks a URL or port that the application does not expose or checks too soon before the application is ready, the container will be repeatedly terminated and restarted. 18 | 19 | ### The Memory Limits Are Too Low 20 | 21 | If the memory limits set for a container are too low, the application might exceed this limit, especially under load, leading to the container being killed by Kubernetes. This can happen repeatedly if the workload does not decrease, causing a cycle of crashing and restarting. Kubernetes uses these limits to ensure that containers do not consume all available resources on a node, which can affect other containers. 22 | 23 | ### Wrong Command Line Arguments 24 | 25 | Containers might be configured to start with specific command-line arguments. If these arguments are wrong or lead to the application exiting (for example, passing an invalid option to a command), the container will exit immediately. Kubernetes will then attempt to restart it, leading to the CrashLoopBackOff status. An example would be passing a configuration file path that does not exist or is inaccessible. 26 | 27 | ### Bugs & Exceptions 28 | 29 | Bugs in the application code, such as unhandled exceptions or segmentation faults, can cause the application to crash. For instance, if the application tries to access a null pointer or fails to catch and handle an exception correctly, it might terminate unexpectedly. Kubernetes, detecting the crash, will restart the container, but if the bug is triggered each time the application runs, this leads to a repetitive crash loop. -------------------------------------------------------------------------------- /02-CrashLoopBackOff/simple-python-app/.dockerignore: -------------------------------------------------------------------------------- 1 | # Include any files or directories that you don't want to be copied to your 2 | # container here (e.g., local build artifacts, temporary files, etc.). 3 | # 4 | # For more help, visit the .dockerignore file reference guide at 5 | # https://docs.docker.com/go/build-context-dockerignore/ 6 | 7 | **/.DS_Store 8 | **/__pycache__ 9 | **/.venv 10 | **/.classpath 11 | **/.dockerignore 12 | **/.env 13 | **/.git 14 | **/.gitignore 15 | **/.project 16 | **/.settings 17 | **/.toolstarget 18 | **/.vs 19 | **/.vscode 20 | **/*.*proj.user 21 | **/*.dbmdl 22 | **/*.jfm 23 | **/bin 24 | **/charts 25 | **/docker-compose* 26 | **/compose* 27 | **/Dockerfile* 28 | **/node_modules 29 | **/npm-debug.log 30 | **/obj 31 | **/secrets.dev.yaml 32 | **/values.dev.yaml 33 | LICENSE 34 | README.md 35 | -------------------------------------------------------------------------------- /02-CrashLoopBackOff/simple-python-app/Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1 2 | 3 | # Comments are provided throughout this file to help you get started. 4 | # If you need more help, visit the Dockerfile reference guide at 5 | # https://docs.docker.com/go/dockerfile-reference/ 6 | 7 | # Want to help us make this template better? Share your feedback here: https://forms.gle/ybq9Krt8jtBL3iCk7 8 | 9 | ARG PYTHON_VERSION=3.10.0 10 | FROM python:${PYTHON_VERSION}-slim as base 11 | 12 | # Prevents Python from writing pyc files. 13 | ENV PYTHONDONTWRITEBYTECODE=1 14 | 15 | # Keeps Python from buffering stdout and stderr to avoid situations where 16 | # the application crashes without emitting any logs due to buffering. 17 | ENV PYTHONUNBUFFERED=1 18 | 19 | WORKDIR /app 20 | 21 | # Create a non-privileged user that the app will run under. 22 | # See https://docs.docker.com/go/dockerfile-user-best-practices/ 23 | ARG UID=10001 24 | RUN adduser \ 25 | --disabled-password \ 26 | --gecos "" \ 27 | --home "/nonexistent" \ 28 | --shell "/sbin/nologin" \ 29 | --no-create-home \ 30 | --uid "${UID}" \ 31 | appuser 32 | 33 | # Download dependencies as a separate step to take advantage of Docker's caching. 34 | # Leverage a cache mount to /root/.cache/pip to speed up subsequent builds. 35 | # Leverage a bind mount to requirements.txt to avoid having to copy them into 36 | # into this layer. 37 | RUN --mount=type=cache,target=/root/.cache/pip \ 38 | --mount=type=bind,source=requirements.txt,target=requirements.txt \ 39 | python -m pip install -r requirements.txt 40 | 41 | # Switch to the non-privileged user to run the application. 42 | USER appuser 43 | 44 | # Copy the source code into the container. 45 | COPY . . 46 | 47 | # Expose the port that the application listens on. 48 | EXPOSE 8000 49 | 50 | # Run the application. 51 | CMD python3 app.py 52 | -------------------------------------------------------------------------------- /02-CrashLoopBackOff/simple-python-app/README.Docker.md: -------------------------------------------------------------------------------- 1 | ### Building and running your application 2 | 3 | When you're ready, start your application by running: 4 | `docker compose up --build`. 5 | 6 | Your application will be available at http://localhost:8000. 7 | 8 | ### Deploying your application to the cloud 9 | 10 | First, build your image, e.g.: `docker build -t myapp .`. 11 | If your cloud uses a different CPU architecture than your development 12 | machine (e.g., you are on a Mac M1 and your cloud provider is amd64), 13 | you'll want to build the image for that platform, e.g.: 14 | `docker build --platform=linux/amd64 -t myapp .`. 15 | 16 | Then, push it to your registry, e.g. `docker push myregistry.com/myapp`. 17 | 18 | Consult Docker's [getting started](https://docs.docker.com/go/get-started-sharing/) 19 | docs for more detail on building and pushing. 20 | 21 | ### References 22 | * [Docker's Python guide](https://docs.docker.com/language/python/) -------------------------------------------------------------------------------- /02-CrashLoopBackOff/simple-python-app/app.py: -------------------------------------------------------------------------------- 1 | from flask import Flask 2 | 3 | app = Flask(__name__) 4 | 5 | @app.route('/') 6 | def hello_world(): 7 | return 'Hello, World!' 8 | 9 | if __name__ == '__main__': 10 | app.run(debug=True, host='0.0.0.0', port=8000) -------------------------------------------------------------------------------- /02-CrashLoopBackOff/simple-python-app/compose.yaml: -------------------------------------------------------------------------------- 1 | # Comments are provided throughout this file to help you get started. 2 | # If you need more help, visit the Docker Compose reference guide at 3 | # https://docs.docker.com/go/compose-spec-reference/ 4 | 5 | # Here the instructions define your application as a service called "server". 6 | # This service is built from the Dockerfile in the current directory. 7 | # You can add other services your application may depend on here, such as a 8 | # database or a cache. For examples, see the Awesome Compose repository: 9 | # https://github.com/docker/awesome-compose 10 | services: 11 | server: 12 | build: 13 | context: . 14 | ports: 15 | - 8000:8000 16 | 17 | # The commented out section below is an example of how to define a PostgreSQL 18 | # database that your application can use. `depends_on` tells Docker Compose to 19 | # start the database before your application. The `db-data` volume persists the 20 | # database data between container restarts. The `db-password` secret is used 21 | # to set the database password. You must create `db/password.txt` and add 22 | # a password of your choosing to it before running `docker compose up`. 23 | # depends_on: 24 | # db: 25 | # condition: service_healthy 26 | # db: 27 | # image: postgres 28 | # restart: always 29 | # user: postgres 30 | # secrets: 31 | # - db-password 32 | # volumes: 33 | # - db-data:/var/lib/postgresql/data 34 | # environment: 35 | # - POSTGRES_DB=example 36 | # - POSTGRES_PASSWORD_FILE=/run/secrets/db-password 37 | # expose: 38 | # - 5432 39 | # healthcheck: 40 | # test: [ "CMD", "pg_isready" ] 41 | # interval: 10s 42 | # timeout: 5s 43 | # retries: 5 44 | # volumes: 45 | # db-data: 46 | # secrets: 47 | # db-password: 48 | # file: db/password.txt 49 | 50 | -------------------------------------------------------------------------------- /02-CrashLoopBackOff/simple-python-app/requirements.txt: -------------------------------------------------------------------------------- 1 | Flask==2.1.0 2 | Werkzeug==2.2.2 -------------------------------------------------------------------------------- /03-pods-not-schedulable/01-kind-cluster.yaml: -------------------------------------------------------------------------------- 1 | kind: Cluster 2 | apiVersion: kind.x-k8s.io/v1alpha4 3 | nodes: 4 | - role: control-plane 5 | - role: worker 6 | - role: worker 7 | - role: worker -------------------------------------------------------------------------------- /03-pods-not-schedulable/02-node-selector.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: nginx-deployment 5 | labels: 6 | app: nginx 7 | spec: 8 | replicas: 3 9 | selector: 10 | matchLabels: 11 | app: nginx 12 | template: 13 | metadata: 14 | labels: 15 | app: nginx 16 | spec: 17 | nodeSelector: 18 | foo: bar 19 | containers: 20 | - name: nginx 21 | image: nginx:1.14.2 22 | ports: 23 | - containerPort: 80 24 | 25 | -------------------------------------------------------------------------------- /03-pods-not-schedulable/03-node-affinity-preferred.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: nginx-deployment 5 | labels: 6 | app: nginx 7 | spec: 8 | replicas: 3 9 | selector: 10 | matchLabels: 11 | app: nginx 12 | template: 13 | metadata: 14 | labels: 15 | app: nginx 16 | spec: 17 | affinity: 18 | nodeAffinity: 19 | preferredDuringSchedulingIgnoredDuringExecution: 20 | - weight: 1 21 | preference: 22 | matchExpressions: 23 | - key: foo 24 | operator: In 25 | values: 26 | - bar 27 | containers: 28 | - name: nginx 29 | image: nginx:1.14.2 30 | ports: 31 | - containerPort: 80 -------------------------------------------------------------------------------- /03-pods-not-schedulable/04-node-affinity-required.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: nginx-deployment 5 | labels: 6 | app: nginx 7 | spec: 8 | replicas: 3 9 | selector: 10 | matchLabels: 11 | app: nginx 12 | template: 13 | metadata: 14 | labels: 15 | app: nginx 16 | spec: 17 | affinity: 18 | nodeAffinity: 19 | requiredDuringSchedulingIgnoredDuringExecution: 20 | nodeSelectorTerms: 21 | - matchExpressions: 22 | - key: foo 23 | operator: In 24 | values: 25 | - bar1 26 | -------------------------------------------------------------------------------- /03-pods-not-schedulable/README.md: -------------------------------------------------------------------------------- 1 | In Kubernetes, the scheduler is responsible for assigning pods to nodes in the cluster based on various criteria. Sometimes, you might encounter situations where pods are not being scheduled as expected. This can happen due to factors such as node constraints, pod requirements, or cluster configurations. 2 | 3 | 1. Node Selector 4 | 5 | Node Selector is a simple way to constrain pods to nodes with specific labels. It allows you to specify a set of key-value pairs that must match the node's labels for a pod to be scheduled on that node. 6 | Usage: Include a nodeSelector field in the pod's YAML definition to specify the required labels. 7 | 8 | ``` 9 | spec: 10 | containers: 11 | - name: my-app 12 | image: my-image 13 | nodeSelector: 14 | disktype: ssd 15 | ``` 16 | 17 | 2. Node Affinity 18 | 19 | Node Affinity is a more expressive way to specify rules about the placement of pods relative to nodes' labels. It allows you to specify rules that apply only if certain conditions are met. 20 | Usage: Define nodeAffinity rules in the pod's YAML definition, specifying required and preferred node selectors. 21 | 22 | ``` 23 | spec: 24 | containers: 25 | - name: my-app 26 | image: my-image 27 | affinity: 28 | nodeAffinity: 29 | requiredDuringSchedulingIgnoredDuringExecution: 30 | nodeSelectorTerms: 31 | - matchExpressions: 32 | - key: disktype 33 | operator: In 34 | values: 35 | - ssd 36 | ``` 37 | 38 | 3. Taints 39 | 40 | Taints are applied to nodes to repel certain pods. They allow nodes to refuse pods unless the pods have a matching toleration. 41 | Usage: Use kubectl taint command to apply taints to nodes. Include tolerations field in the pod's YAML definition to tolerate specific taints. 42 | 43 | ``` 44 | kubectl taint nodes node1 disktype=ssd:NoSchedule 45 | ``` 46 | 47 | ``` 48 | spec: 49 | containers: 50 | - name: my-app 51 | image: my-image 52 | tolerations: 53 | - key: disktype 54 | operator: Equal 55 | value: ssd 56 | effect: NoSchedule 57 | ``` 58 | 59 | 4. Tolerations 60 | 61 | Tolerations are applied to pods and allow them to schedule onto nodes with matching taints. They override the effect of taints. 62 | 63 | Usage: Include tolerations field in the pod's YAML definition to specify which taints the pod tolerates. 64 | 65 | ``` 66 | spec: 67 | containers: 68 | - name: my-app 69 | image: my-image 70 | tolerations: 71 | - key: disktype 72 | operator: Equal 73 | value: ssd 74 | effect: NoSchedule 75 | ``` -------------------------------------------------------------------------------- /04-statefulset-pv/sample-statefulset.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: StatefulSet 3 | metadata: 4 | name: web 5 | spec: 6 | selector: 7 | matchLabels: 8 | app: nginx 9 | serviceName: "nginx" 10 | replicas: 3 11 | minReadySeconds: 10 12 | template: 13 | metadata: 14 | labels: 15 | app: nginx 16 | spec: 17 | terminationGracePeriodSeconds: 10 18 | containers: 19 | - name: nginx 20 | image: registry.k8s.io/nginx-slim:0.8 21 | ports: 22 | - containerPort: 80 23 | name: web 24 | volumeMounts: 25 | - name: www 26 | mountPath: /usr/share/nginx/html 27 | volumeClaimTemplates: 28 | - metadata: 29 | name: www 30 | spec: 31 | accessModes: [ "ReadWriteOnce" ] 32 | storageClassName: ebs 33 | resources: 34 | requests: 35 | storage: 1Gi -------------------------------------------------------------------------------- /05-networkpolicy/db.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: redis 5 | labels: 6 | app: redis 7 | spec: 8 | replicas: 1 9 | selector: 10 | matchLabels: 11 | app: redis 12 | template: 13 | metadata: 14 | labels: 15 | app: redis 16 | spec: 17 | containers: 18 | - name: redis 19 | image: "docker.io/redis:6.0.5" 20 | ports: 21 | - containerPort: 6379 22 | -------------------------------------------------------------------------------- /05-networkpolicy/hack.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: nginx-deployment 5 | spec: 6 | selector: 7 | matchLabels: 8 | app: nginx 9 | replicas: 1 10 | template: 11 | metadata: 12 | labels: 13 | app: nginx 14 | spec: 15 | containers: 16 | - name: nginx 17 | image: nginx:1.14.2 18 | ports: 19 | - containerPort: 80 20 | -------------------------------------------------------------------------------- /05-networkpolicy/network-policy.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: networking.k8s.io/v1 2 | kind: NetworkPolicy 3 | metadata: 4 | name: redis-network-policy 5 | namespace: default 6 | spec: 7 | podSelector: 8 | matchLabels: 9 | app: redis 10 | policyTypes: 11 | - Ingress 12 | ingress: 13 | - from: 14 | - podSelector: 15 | matchLabels: 16 | role: known-redis-member 17 | ports: 18 | - protocol: TCP 19 | port: 6379 -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # kubernetes-troubleshooting-zero-to-hero 2 | Learn how to troubleshoot the most common Kubernetes Issues 3 | 4 | ## Day-01 5 | 6 | ### ImagePullBackOff 7 | 8 | Video Link - https://youtu.be/vGab4v3RWEw 9 | 10 | When a kubelet starts creating containers for a Pod using a container runtime, it might be possible the container is in Waiting state because of ImagePullBackOff. 11 | 12 | The status ImagePullBackOff means that a container could not start because Kubernetes could not pull a container image for reasons such as 13 | 14 | - Invalid image name or 15 | - Pulling from a private registry without imagePullSecret. 16 | 17 | The BackOff part indicates that Kubernetes will keep trying to pull the image, with an increasing back-off delay. 18 | 19 | Kubernetes raises the delay between each attempt until it reaches a compiled-in limit, which is 300 seconds (5 minutes). 20 | 21 | 22 | ## Day-02 23 | 24 | ### CrashLoopBackOff 25 | 26 | When you see "CrashLoopBackOff," it means that kubelet is trying to run the container, but it keeps failing and crashing. After crashing, Kubernetes tries to restart the container automatically, but if the container keeps failing repeatedly, you end up in a loop of crashes and restarts, thus the term "CrashLoopBackOff." 27 | 28 | This situation indicates that something is wrong with the application or the configuration that needs to be fixed. 29 | 30 | ## Day-03 31 | 32 | ### Pods not schedulable 33 | 34 | In Kubernetes, the scheduler is responsible for assigning pods to nodes in the cluster based on various criteria. Sometimes, you might encounter situations where pods are not being scheduled as expected. This can happen due to factors such as node constraints, pod requirements, or cluster configurations. 35 | 36 | 1. Node Selector 37 | 2. Node Affinity 38 | 3. Taints 39 | 4. Tolerations 40 | --------------------------------------------------------------------------------