-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
655 additions
and
0 deletions.
There are no files selected for viewing
114 changes: 114 additions & 0 deletions
114
bundles/kubernetes-101/labs/creating-and-managing-deployments.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,114 @@ | ||
# Creating and Managing Deployments | ||
|
||
Deployments abstract away the low level details of managing Pods. Pods are tied to the lifetime of the node they are created on. When the node goes away so does the Pod. ReplicaSets can be used to ensure one or more replicas of a Pods are always running, even when nodes fail. | ||
|
||
Deployments sit on top of ReplicaSets and add the ability to define how updates to Pods should be rolled out. | ||
|
||
In this lab we will combine everything we learned about Pods and Services to breakup the monolith application into smaller Services. You will create 3 deployments, one for each service: | ||
|
||
* frontend | ||
* auth | ||
* hello | ||
|
||
You will also define internal services for the `auth` and `hello` deployments and an external service for the `frontend` deployment. | ||
|
||
## Tutorial: Creating Deployments | ||
|
||
### Create and Expose the Auth Deployment | ||
|
||
``` | ||
kubectl create -f deployments/auth.yaml | ||
``` | ||
|
||
``` | ||
kubectl describe deployments auth | ||
``` | ||
|
||
``` | ||
kubectl create -f services/auth.yaml | ||
``` | ||
|
||
### Create and Expose the Hello Deployment | ||
|
||
``` | ||
kubectl create -f deployments/hello.yaml | ||
``` | ||
|
||
``` | ||
kubectl describe deployments hello | ||
``` | ||
|
||
``` | ||
kubectl create -f services/hello.yaml | ||
``` | ||
|
||
### Create and Expose the Frontend Deployment | ||
|
||
|
||
``` | ||
kubectl create configmap nginx-frontend-conf --from-file=nginx/frontend.conf | ||
``` | ||
|
||
``` | ||
kubectl create -f deployments/frontend.yaml | ||
``` | ||
|
||
``` | ||
kubectl create -f services/frontend.yaml | ||
``` | ||
|
||
## Tutorial: Scaling Deployments | ||
|
||
Behind the scenes Deployments manage ReplicaSets. Each deployment is mapped to one active ReplicaSet. Use the `kubectl get replicasets` command to view the current set of replicas. | ||
|
||
``` | ||
kubectl get replicasets | ||
``` | ||
|
||
ReplicaSets are scaled through the Deployment for each service and can be scaled independently. Use the `kubectl scale` command to scale the hello deployment: | ||
|
||
``` | ||
kubectl scale deployments hello --replicas=3 | ||
``` | ||
|
||
``` | ||
kubectl describe deployments hello | ||
``` | ||
|
||
``` | ||
kubectl get pods | ||
``` | ||
|
||
``` | ||
kubectl get replicasets | ||
``` | ||
|
||
## Exercise: Scaling Deployments | ||
|
||
In this exercise you will scale the `frontend` deployment using an existing deployment configuration file. | ||
|
||
### Hints | ||
|
||
``` | ||
vim deployments/frontend.yaml | ||
``` | ||
|
||
``` | ||
kubectl apply -f deployments/frontend.yaml | ||
``` | ||
|
||
## Exercise: Interact with the Frontend Service | ||
|
||
### Hints | ||
|
||
``` | ||
kubectl get services frontend | ||
``` | ||
|
||
``` | ||
curl -k https://<EXTERNAL-IP> | ||
``` | ||
|
||
## Summary | ||
|
||
Deployments are the preferred way to manage application deployments. You learned how to create, expose and scale deployments. |
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,95 @@ | ||
# Creating and managing pods | ||
|
||
At the core of Kubernetes is the Pod. Pods represent a logical application and hold a collection of one or more containers and volumes. In this lab you will learn how to: | ||
|
||
* Write a Pod configuration file | ||
* Create and inspect Pods | ||
* Interact with Pods remotely using kubectl | ||
|
||
In this lab you will create a Pod named `monolith` and interact with it using the kubectl command line tool. | ||
|
||
## Tutorial: Creating Pods | ||
|
||
Explore the `monolith` pod configuration file: | ||
|
||
``` | ||
cat pods/monolith.yaml | ||
``` | ||
|
||
Create the `monolith` pod using kubectl: | ||
|
||
``` | ||
kubectl create -f pods/monolith.yaml | ||
``` | ||
|
||
## Exercise: View Pod details | ||
|
||
Use the `kubectl get` and `kubect describe` commands to view details for the `monolith` Pod: | ||
|
||
### Hints | ||
|
||
``` | ||
kubectl get pods | ||
``` | ||
|
||
``` | ||
kubectl describe pods <pod-name> | ||
``` | ||
|
||
### Quiz | ||
|
||
* What is the IP address of the `monolith` Pod? | ||
* What node is the `monolith` Pod running on? | ||
* What containers are running in the `monolith` Pod? | ||
* What are the labels attached to the `monolith` Pod? | ||
* What arguments are set on the `monolith` container? | ||
|
||
## Exercise: Interact with a Pod remotely | ||
|
||
Pods are allocated a private IP address by default and cannot be reached outside of the cluster. Use the `kubectl port-forward` command to map a local port to a port inside the `monolith` pod. | ||
|
||
### Hints | ||
|
||
Use two terminals. One to run the `kubectl port-forward` command, and the other to issue `curl` commands. | ||
|
||
``` | ||
kubectl port-forward monolith 10080:80 | ||
``` | ||
|
||
``` | ||
curl http://127.0.0.1:10080 | ||
``` | ||
|
||
``` | ||
curl http://127.0.0.1:10080/secure | ||
``` | ||
|
||
``` | ||
curl -u user http://127.0.0.1:10080/login | ||
``` | ||
|
||
> Type "password" at the prompt. | ||
``` | ||
curl -H "Authorization: Bearer <token>" http://127.0.0.1:10080/secure | ||
``` | ||
|
||
> Use the JWT token from the previous login. | ||
## Exercise: View the logs of a Pod | ||
|
||
Use the `kubectl logs` command to view the logs for the `monolith` Pod: | ||
|
||
``` | ||
kubectl logs monolith | ||
``` | ||
|
||
> Use the -f flag and observe what happens. | ||
## Exercise: Run an interactive shell inside a Pod | ||
|
||
Use the `kubectl exec` command to run an interactive shell inside the `monolith` Pod: | ||
|
||
``` | ||
kubectl exec monolith --stdin --tty -c monolith /bin/sh | ||
``` |
128 changes: 128 additions & 0 deletions
128
bundles/kubernetes-101/labs/creating-and-managing-services.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,128 @@ | ||
# Creating and Managing Services | ||
|
||
Services provide stable endpoints for Pods based on a set of labels. | ||
|
||
In this lab you will create the `monolith` service and "expose" the `secure-monolith` Pod externally. You will learn how to: | ||
|
||
* Create a service | ||
* Use label selectors to expose a limited set of Pods externally | ||
|
||
## Tutorial: Create a Service | ||
|
||
Explore the monolith service configuration file: | ||
|
||
``` | ||
cat services/monolith.yaml | ||
``` | ||
|
||
Create the monolith service using kubectl: | ||
|
||
``` | ||
kubectl create -f services/monolith.yaml | ||
``` | ||
|
||
Use the `gcloud compute firewall-rules` command to allow traffic to the `monolith` service: | ||
|
||
``` | ||
gcloud compute firewall-rules create allow-monolith-nodeport \ | ||
--allow=tcp:31000 | ||
``` | ||
|
||
## Exercise: Interact with the Monolith Service Remotely | ||
|
||
### Hints | ||
|
||
``` | ||
gcloud compute instances list | ||
``` | ||
|
||
``` | ||
curl -k https://<EXTERNAL_IP>:31000 | ||
``` | ||
|
||
### Quiz | ||
|
||
* Why are you unable to get a response from the `monolith` service? | ||
|
||
## Exercise: Explore the monolith Service | ||
|
||
### Hints | ||
|
||
``` | ||
kubectl get services monolith | ||
``` | ||
|
||
``` | ||
kubectl describe services monolith | ||
``` | ||
|
||
### Quiz | ||
|
||
* How many endpoints does the `monolith` service have? | ||
* What labels must a Pod have to be picked up by the `monolith` service? | ||
|
||
## Tutorial: Add Labels to Pods | ||
|
||
Currently the `monolith` service does not have any endpoints. One way to troubleshoot an issue like this is to use the `kubectl get pods` command with a label query. | ||
|
||
``` | ||
kubectl get pods -l "app=monolith" | ||
``` | ||
|
||
``` | ||
kubectl get pods -l "app=monolith,secure=enabled" | ||
``` | ||
|
||
> Notice this label query does not print any results | ||
Use the `kubectl label` command to add the missing `secure=enabled` label to the `secure-monolith` Pod. | ||
|
||
``` | ||
kubectl label pods secure-monolith 'secure=enabled' | ||
``` | ||
|
||
View the list of endpoints on the `monolith` service: | ||
|
||
``` | ||
kubectl describe services monolith | ||
``` | ||
|
||
### Quiz | ||
|
||
* How many endpoints does the `monolith` service have? | ||
|
||
## Exercise: Interact with the Monolith Service Remotely | ||
|
||
### Hints | ||
|
||
``` | ||
gcloud compute instances list | ||
``` | ||
|
||
``` | ||
curl -k https://<EXTERNAL_IP>:31000 | ||
``` | ||
|
||
## Tutorial: Remove Labels from Pods | ||
|
||
In this exercise you will observe what happens when a required label is removed from a Pod. | ||
|
||
Use the `kubectl label` command to remove the `secure` label from the `secure-monolith` Pod. | ||
|
||
``` | ||
kubectl label pods secure-monolith secure- | ||
``` | ||
|
||
View the list of endpoints on the `monolith` service: | ||
|
||
``` | ||
kubectl describe services monolith | ||
``` | ||
|
||
### Quiz | ||
|
||
* How many endpoints does the `monolith` service have? | ||
|
||
## Summary | ||
|
||
In this lab you learned how to expose Pods using services and labels. |
Oops, something went wrong.