-
Familiarity with a Container runtime (e.g. Docker)
-
Minikube - Minikube has its own pre-requisites. Please check this page. If you have problems installing Minikube locally, you can use the Katakoda terminal provided on https://kubernetes.io/docs/tutorials/hello-minikube/#create-a-minikube-cluster however you may have problems running the port forward command later.
- Kubernetes Architecture
- Namespaces
- Pods
- ReplicaSets
- Deployments
- Create
- Describe
- Rolling Update Strategies
- Services
- Port forward
- Editing Deployments
- Edit
- Rollout
- Scale Deployment up and Down
Clone this repository with git clone https://github.com/Jenniferstrej/nginx-examples-kube.git
Kubernetes reference docs are excellent and will often provide all the information you need: https://kubernetes.io
https://slides.com/jenniferstrejevitch/kubernetes-architecture/live
Create a namespace called class
(Answer: Run kubectl create namespace class
)
Create a pod manifest with the image jenniferstrej/jen-nginx:1.1
(Answer: https://github.com/Jenniferstrej/nginx-examples-kube/blob/1.1/jen-nginx-pod.yaml)
Create the pod on your Minikube cluster under the class
namespace
(Answer: kubectl apply -f jen-nginx-pod.yaml -n class
)
Try to delete the pod above. What happens?
(Answer: kubectl -n class delete pod jen-nginx-[podid]
. The pod is deleted and is not recreated.)
Create a ReplicaSet.
(Answer: Go to https://github.com/Jenniferstrej/nginx-examples-kube/blob/1.1/jen-nginx-rs.yaml and kubectl -n class apply -f jen-nginx-rs.yaml
)
Try to delete the pod above. It should be recreated now.
Create a deployment of the image jenniferstrej/jen-nginx:1.1 with 3 replicas
(Answer: Create this file locally https://github.com/Jenniferstrej/nginx-examples-kube/blob/1.1/jen-nginx-deploy.yaml and run kubectl -n class apply -f jen-nginx-rs.yaml
)
Rolling Update Strategies
Run kubectl describe deployment jen-nginx
Default rolling update strategy is "RollingUpdateStrategy: 25% max unavailable, 25% max surge". What does it mean?
(Answer: When updating my deployment the pods will be gradually replaced so my application stays available at all time. It may show both versions for a short period.)
See documentation of Rolling Update strategies https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#updating-a-deployment.
A pod is visible to the Cluster via its pod IP, however that information is not reliable for a long period of time. We need a way to have our pod (or more pods if part of a ReplicaSet) reacheable via a cluster wide IP.
Exercise: Expose jen-nginx pods on port 80.
(Answer: Create this file locally https://github.com/Jenniferstrej/nginx-examples-kube/blob/1.1/jen-nginx-svc.yaml and run kubectl -n class apply -f jen-nginx-svc.yaml
)
You can use Port forwarding to access applications in a cluster. We will forward a local port to a port on the pod. We know our pod exposes port 80. We will forward our local port 8080 to our jen-nginx pods.
Run kubectl -n class port-forward service/jen-nginx 8080:80
Open your browser on the address http://127.0.0.1:8080/
You should see our welcome page.
Now that we have some user level visibility of our deployed application, let's deploy a new version of our app, using the docker image jenniferstrej/jen-nginx:1.2
Edit jen-nginx deployment with the image jenniferstrej/jen-nginx:1.2
(Answers (2 options):
- Edit the
jen-nginx-deploy.yaml
and update the field image with the new version, then runkubectl -n class apply -f jen-nginx-deploy.yaml
. File should look like https://github.com/Jenniferstrej/nginx-examples-kube/blob/1.2/jen-nginx-deploy.yaml - (imperative)
kubectl -n class edit deployment jen-nginx
and interactivelly edit the field image then save the file)
Run kubectl rollout status deployment/jen-nginx
You should see something like:
Waiting for deployment "jen-nginx" rollout to finish: 1 out of 3 new replicas have been updated...
Waiting for deployment "jen-nginx" rollout to finish: 1 out of 3 new replicas have been updated...
Waiting for deployment "jen-nginx" rollout to finish: 1 out of 3 new replicas have been updated...
Waiting for deployment "jen-nginx" rollout to finish: 2 out of 3 new replicas have been updated...
Waiting for deployment "jen-nginx" rollout to finish: 2 out of 3 new replicas have been updated...
Waiting for deployment "jen-nginx" rollout to finish: 2 out of 3 new replicas have been updated...
Waiting for deployment "jen-nginx" rollout to finish: 1 old replicas are pending termination...
Waiting for deployment "jen-nginx" rollout to finish: 1 old replicas are pending termination...
deployment "jen-nginx" successfully rolled out
Reload the app on the browser (if you stopped port forwarding run the command again so you can see your app on the web page)
You should see a background color change on the page.
Rolling back a deployment
Run kubectl rollout history deployment/jen-nginx
Observe your previous deployment revision
REVISION CHANGE-CAUSE
[Number] <none>
Rollback this deployment to the previous version
kubectl rollout undo deployment/jen-nginx
Check the status: kubectl rollout status deployment/jen-nginx
Reload your web page. It should display the page with a white background again.
Scale Deployment
Depending on the needs of your app (e.g. redundancy, resource needs, etc.) you may want to scale it down or up. Currently our deployment is running 3 pods. Let's reduce the number to 2 pods.
Exercise: Scale deployment jen-nginx to 2 pods.
(Answers (2 options):
kubectl -n class scale deployment jen-nginx --replicas=2
- Edit
jen-nginx-deploy.yaml
file and set the fieldreplicas
to 2, save and runkubectl apply -f jen-nginx-deploy.yaml
)
[TODO]
[TODO]