forked from NotHarshhaa/into-the-devops
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IntoTheDevOps: Add End-to-End Kubernetes content
Signed-off-by: NotHarshhaa <reddyharshhaa12@gmail.com>
- Loading branch information
1 parent
52e27c3
commit 44863a4
Showing
28 changed files
with
4,509 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
topics/kubernetes/exercises/kustomize_common_labels/exercise.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Kustomize - Common Labels | ||
|
||
## Requirements | ||
|
||
1. Running Kubernetes cluster | ||
2. Kubctl version 1.14 or above | ||
|
||
## Objectives | ||
|
||
In the current directory there is an app composed of a Deployment and Service. | ||
|
||
1. Write a kustomization.yml file that will add to both the Service and Deployment the label "team-name: aces" | ||
2. Execute a kustomize command that will generate the customized k8s files with the label appended | ||
|
||
## Solution | ||
|
||
Click [here](solution.md) to view the solution |
31 changes: 31 additions & 0 deletions
31
topics/kubernetes/exercises/kustomize_common_labels/solution.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Kustomize - Common Labels | ||
|
||
## Requirements | ||
|
||
1. Running Kubernetes cluster | ||
2. Kubctl version 1.14 or above | ||
|
||
## Objectives | ||
|
||
In the current directory there is an app composed of a Deployment and Service. | ||
|
||
1. Write a kustomization.yml file that will add to both the Service and Deployment the label "team-name: aces" | ||
2. Execute a kustomize command that will generate the customized k8s files with the label appended | ||
|
||
## Solution | ||
|
||
1. Add the following to kustomization.yml in someApp directory: | ||
|
||
``` | ||
apiVersion: kustomize.config.k8s.io/v1beta1 | ||
kind: Kustomization | ||
commonLabels: | ||
team-name: aces | ||
resources: | ||
- service.yml | ||
- deployment.yml | ||
``` | ||
|
||
2. Run `kubectl apply -k someApp` |
21 changes: 21 additions & 0 deletions
21
topics/kubernetes/exercises/kustomize_common_labels/someApp/deployment.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: nginx-deployment | ||
labels: | ||
app: nginx | ||
spec: | ||
replicas: 3 | ||
selector: | ||
matchLabels: | ||
app: nginx | ||
template: | ||
metadata: | ||
labels: | ||
app: nginx | ||
spec: | ||
containers: | ||
- name: nginx | ||
image: nginx:1.14.2 | ||
ports: | ||
- containerPort: 80 |
11 changes: 11 additions & 0 deletions
11
topics/kubernetes/exercises/kustomize_common_labels/someApp/service.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: my-service | ||
spec: | ||
selector: | ||
app: nginx | ||
ports: | ||
- protocol: TCP | ||
port: 80 | ||
targetPort: 9376 |
11 changes: 11 additions & 0 deletions
11
topics/kubernetes/exercises/labels_and_selectors/exercise.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Labels and Selectors 101 | ||
|
||
## Objectives | ||
|
||
1. How to list all the Pods with the label "app=web"? | ||
2. How to list all objects labeled as "env=staging"? | ||
3. How to list all deployments from "env=prod" and "type=web"? | ||
|
||
## Solution | ||
|
||
Click [here](solution.md) to view the solution. |
13 changes: 13 additions & 0 deletions
13
topics/kubernetes/exercises/labels_and_selectors/solution.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Labels and Selectors 101 | ||
|
||
## Objectives | ||
|
||
1. How to list all the Pods with the label "app=web"? | ||
2. How to list all objects labeled as "env=staging"? | ||
3. How to list all deployments from "env=prod" and "type=web"? | ||
|
||
## Solution | ||
|
||
`k get po -l app=web` | ||
`k get all -l env=staging` | ||
`k get deploy -l env=prod,type=web` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Node Selectors | ||
|
||
## Objectives | ||
|
||
1. Apply the label "hw=max" on one of the nodes in your cluster | ||
2. Create and run a Pod called `some-pod` with the image `redis` and configure it to use the selector `hw=max` | ||
3. Explain why node selectors might be limited | ||
|
||
|
||
## Solution | ||
|
||
Click [here](solution.md) to view the solution |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Node Selectors | ||
|
||
## Objectives | ||
|
||
1. Apply the label "hw=max" on one of the nodes in your cluster | ||
2. Create and run a Pod called `some-pod` with the image `redis` and configure it to use the selector `hw=max` | ||
3. Explain why node selectors might be limited | ||
|
||
|
||
## Solution | ||
|
||
Click [here](solution.md) to view the solution | ||
|
||
1. `kubectl label nodes some-node hw=max` | ||
2. | ||
|
||
``` | ||
kubectl run some-pod --image=redis --dry-run=client -o yaml > pod.yaml | ||
vi pod.yaml | ||
spec: | ||
nodeSelector: | ||
hw: max | ||
kubectl apply -f pod.yaml | ||
``` | ||
|
||
3. Assume you would like to run your Pod on all the nodes with with either `hw` set to max or to min, instead of just max. This is not possible with nodeSelectors which are quite simplified and this is where you might want to consider `node affinity`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Taints 101 | ||
|
||
## Objectives | ||
|
||
1. Check if one of the nodes in the cluster has taints (doesn't matter which node) | ||
2. Create a taint on one of the nodes in your cluster with key of "app" and value of "web" and effect of "NoSchedule" | ||
1. Explain what it does exactly | ||
2. Verify it was applied | ||
3. Run a Pod that will be able to run on the node on which you applied the taint | ||
|
||
## Solution | ||
|
||
Click [here](solution.md) to view the solution. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Taints 101 | ||
|
||
## Objectives | ||
|
||
1. Check if one of the nodes in the cluster has taints (doesn't matter which node) | ||
2. Create a taint on one of the nodes in your cluster with key of "app" and value of "web" and effect of "NoSchedule" | ||
1. Explain what it does exactly | ||
2. Verify it was applied | ||
|
||
## Solution | ||
|
||
1. `kubectl describe no minikube | grep -i taints` | ||
2. `kubectl taint node minikube app=web:NoSchedule` | ||
1. Any resource with "app=web" key value will not be scheduled on node `minikube` | ||
2. `kubectl describe no minikube | grep -i taints` | ||
3. | ||
|
||
``` | ||
kubectl run some-pod --image=redis | ||
kubectl edit po some-pod | ||
``` | ||
|
||
``` | ||
- effect: NoSchedule | ||
key: app | ||
operator: Equal | ||
value: web | ||
``` | ||
|
||
Save and exit. The Pod should be running. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
## "Killing" Containers | ||
|
||
1. Run Pod with a web service (e.g. httpd) | ||
2. Verify the web service is running with the `ps` command | ||
3. Check how many restarts the pod has performed | ||
4. Kill the web service process | ||
5. Check how many restarts the pod has performed | ||
6. Verify again the web service is running | ||
|
||
## After you complete the exercise | ||
|
||
* Why did the "RESTARTS" count raised? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
## Pods 01 | ||
|
||
#### Objective | ||
|
||
Learn how to create pods | ||
|
||
#### Instructions | ||
|
||
1. Choose a container image (e.g. redis, nginx, mongo, etc.) | ||
2. Create a pod (in the default namespace) using the image you chose | ||
3. Verify the pod is running |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
## ReplicaSet 101 | ||
|
||
#### Objective | ||
|
||
Learn how to create and view ReplicaSets | ||
|
||
#### Instructions | ||
|
||
1. Create a ReplicaSet with 2 replicas. The app can be anything. | ||
2. Verify a ReplicaSet was created and there are 2 replicas | ||
3. Delete one of the Pods the ReplicaSet has created | ||
4. If you'll list all the Pods now, what will you see? | ||
5. Remove the ReplicaSet you've created | ||
6. Verify you've deleted the ReplicaSet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
## ReplicaSet 102 | ||
|
||
#### Objective | ||
|
||
Learn how to operate ReplicaSets | ||
|
||
#### Instructions | ||
|
||
1. Create a ReplicaSet with 2 replicas. The app can be anything. | ||
2. Verify a ReplicaSet was created and there are 2 replicas | ||
3. Remove the ReplicaSet but NOT the pods it created | ||
4. Verify you've deleted the ReplicaSet but the Pods are still running |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
## ReplicaSet 103 | ||
|
||
#### Objective | ||
|
||
Learn how labels used by ReplicaSets | ||
|
||
#### Instructions | ||
|
||
1. Create a ReplicaSet with 2 replicas. Make sure the label used for the selector and in the Pods is "type=web" | ||
2. Verify a ReplicaSet was created and there are 2 replicas | ||
3. List the Pods running | ||
4. Remove the label (type=web) from one of the Pods created by the ReplicaSet | ||
5. List the Pods running. Are there more Pods running after removing the label? Why? | ||
6. Verify the ReplicaSet indeed created a new Pod |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
## Services 01 | ||
|
||
#### Objective | ||
|
||
Learn how to create services | ||
|
||
#### Instructions | ||
|
||
1. Create a pod running ngnix | ||
2. Create a service for the pod you've just created | ||
3. Verify the app is reachable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
## "Killing" Containers - Solution | ||
|
||
1. Run Pod with a web service (e.g. httpd) - `kubectl run web --image registry.redhat.io/rhscl/httpd-24-rhel7` | ||
2. Verify the web service is running with the `ps` command - `kubectl exec web -- ps` | ||
3. Check how many restarts the pod has performed - `kubectl get po web` | ||
4. Kill the web service process -`kubectl exec web -- kill 1` | ||
5. Check how many restarts the pod has performed - `kubectl get po web` | ||
6. Verify again the web service is running - `kubectl exec web -- ps` | ||
|
||
## After you complete the exercise | ||
|
||
* Why did the "RESTARTS" count raised? - `because we killed the process and Kubernetes identified the container isn't running properly so it performed restart to the Pod` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
## Pods 01 - Solution | ||
|
||
``` | ||
kubectl run nginx --image=nginx --restart=Never | ||
kubectl get pods | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
## ReplicaSet 01 - Solution | ||
|
||
1. Create a ReplicaSet with 2 replicas. The app can be anything. | ||
|
||
``` | ||
cat >> rs.yaml <<EOL | ||
apiVersion: apps/v1 | ||
kind: ReplicaSet | ||
metadata: | ||
name: web | ||
labels: | ||
app: somewebapp | ||
type: web | ||
spec: | ||
replicas: 2 | ||
selector: | ||
matchLabels: | ||
type: web | ||
template: | ||
metadata: | ||
labels: | ||
type: web | ||
spec: | ||
containers: | ||
- name: httpd | ||
image: registry.redhat.io/rhscl/httpd-24-rhel7 | ||
EOL | ||
kubectl apply -f rs.yaml | ||
``` | ||
|
||
2. Verify a ReplicaSet was created and there are 2 replicas | ||
|
||
``` | ||
kubectl get rs | ||
# OR a more specific way: kubectl get -f rs.yaml | ||
``` | ||
|
||
3. Delete one of the Pods the ReplicaSet has created | ||
|
||
``` | ||
kubectl delete po <POD_NAME> | ||
``` | ||
|
||
4. If you'll list all the Pods now, what will you see? | ||
|
||
``` | ||
The same number of Pods. Since we defined 2 replicas, the ReplicaSet will make sure to create another Pod that will replace the one you've deleted. | ||
``` | ||
|
||
5. Remove the ReplicaSet you've created | ||
|
||
``` | ||
kubectl delete -f rs.yaml | ||
``` | ||
|
||
6. Verify you've deleted the ReplicaSet | ||
|
||
``` | ||
kubectl get rs | ||
# OR a more specific way: kubectl get -f rs.yaml | ||
``` |
Oops, something went wrong.