lab:kubernetes_app:step_6_-_application_configuration
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
lab:kubernetes_app:step_6_-_application_configuration [2024/02/15 03:21] – [Next Step] user | lab:kubernetes_app:step_6_-_application_configuration [2024/05/13 18:16] (current) – removed user | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Step 6 - Application Configuration ====== | ||
- | // See [[https:// | ||
- | In this step we look at deploying different application images | ||
- | * doritoes/ | ||
- | * doritoes/ | ||
- | * doritoes/ | ||
- | |||
- | Strategies supported by Kubernetes out of the box: | ||
- | * rolling deployment (default) - replaces pods running the older version with the new version one-by-one | ||
- | * recreate deployment - terminates all pods and replaces them with the new version | ||
- | * ramped slow rollout - very safe and slow rollout | ||
- | * best-effort controlled rollout - fast and lower overhead but run during a maintenance window | ||
- | Strategies that requires customization or specialized tools: | ||
- | * blue/green deployment | ||
- | * canary deployment | ||
- | * shadow deployment | ||
- | * A/B testing | ||
- | |||
- | ====== Rolling Deployment ====== | ||
- | ===== Open a Second Session to Monitor the Process ===== | ||
- | Open a second terminal or ssh session and run the watch command | ||
- | < | ||
- | You will watch the status of your deployment here. | ||
- | |||
- | ===== Update the Image in k8s-deployment-web.yml ===== | ||
- | Update '' | ||
- | < | ||
- | |||
- | Here is the entire modified file: | ||
- | <file yaml k8s-deployment-web.yml> | ||
- | apiVersion: apps/v1 | ||
- | kind: Deployment | ||
- | metadata: | ||
- | name: web-deployment | ||
- | spec: | ||
- | replicas: 2 | ||
- | selector: | ||
- | matchLabels: | ||
- | app: web | ||
- | template: | ||
- | metadata: | ||
- | labels: | ||
- | app: web | ||
- | spec: | ||
- | nodeSelector: | ||
- | my-role: worker # restrict scheduling to the nodes with the label my-role: worker | ||
- | containers: | ||
- | - name: web | ||
- | image: doritoes/ | ||
- | ports: | ||
- | - containerPort: | ||
- | livenessProbe: | ||
- | httpGet: | ||
- | path: / | ||
- | port: 8080 | ||
- | initialDelaySeconds: | ||
- | periodSeconds: | ||
- | readinessProbe: | ||
- | httpGet: | ||
- | path: / | ||
- | port: 8080 | ||
- | initialDelaySeconds: | ||
- | periodSeconds: | ||
- | </ | ||
- | |||
- | ===== Kick Off the Update ===== | ||
- | This process will perform a one-by-one replacement. Health checks (liveness and readiness) ensure new pods are healthy before taking old ones offline. | ||
- | |||
- | Start the update | ||
- | < | ||
- | |||
- | Observe the rollout | ||
- | < | ||
- | |||
- | Watch the status in the other session. What can you see, and what useful information is missing? | ||
- | |||
- | Examine the deployment and see which image is running: | ||
- | < | ||
- | |||
- | Here is a way to get the images running on all pods: | ||
- | < | ||
- | kubectl get pods --all-namespaces -o jsonpath=' | ||
- | sort | ||
- | </ | ||
- | ===== Testing and Troubleshooting ===== | ||
- | Load the web app now (either by nodePort or by updating the HAProxy config). | ||
- | |||
- | You may need to press F5 or Control F5 to refresh the style sheet. The color of the app should now be green | ||
- | |||
- | If the rollout is stalled, use these commands to investigate potential issues: | ||
- | < | ||
- | kubectl describe deployment web-deployment | ||
- | kubectl get pods | ||
- | kubectl logs < | ||
- | </ | ||
- | |||
- | ===== Rollback ===== | ||
- | Roll back the update using | ||
- | < | ||
- | kubectl rollout undo deployment/ | ||
- | </ | ||
- | |||
- | Observe the rollback | ||
- | < | ||
- | |||
- | Watch the status in the other session. | ||
- | |||
- | Examine the deployment and see which image is running: | ||
- | < | ||
- | |||
- | Load the web app again and Control-F5/ | ||
- | |||
- | The color should be back to blue. | ||
- | |||
- | ===== Improvements ===== | ||
- | You can customize the rolling deployment behavior within your Deployment spec with the '' | ||
- | |||
- | For example here is adding the ability to add up to 25% of the desired number of pods and ensuring you never drop before the desired number of pods. | ||
- | |||
- | <code yaml> | ||
- | spec: | ||
- | replicas: 2 | ||
- | strategy: | ||
- | type: RollingUpdate | ||
- | rollingUpdate: | ||
- | maxSurge: 25% # Can exceed the desired number of pods | ||
- | maxUnavailable: | ||
- | # ... rest of your deployment specification ... | ||
- | </ | ||
- | |||
- | ====== Replace Deployment ====== | ||
- | This is the ungraceful method to kill all pods and re-create them with no concern as to update. | ||
- | |||
- | ===== Open a Second Session to Monitor the Process ===== | ||
- | Open a second terminal or ssh session and run the watch command | ||
- | < | ||
- | You will watch the status of your deployment here. | ||
- | |||
- | ===== Create the Update ===== | ||
- | We will make a new version of '' | ||
- | < | ||
- | strategy: | ||
- | type: Recreate | ||
- | </ | ||
- | |||
- | We will deploy the " | ||
- | |||
- | Here is the complete file: | ||
- | <file yaml k8s-replace-web-web.yml> | ||
- | apiVersion: apps/v1 | ||
- | kind: Deployment | ||
- | metadata: | ||
- | name: web-deployment | ||
- | spec: | ||
- | replicas: 2 | ||
- | strategy: | ||
- | type: Recreate | ||
- | selector: | ||
- | matchLabels: | ||
- | app: web | ||
- | template: | ||
- | metadata: | ||
- | labels: | ||
- | app: web | ||
- | spec: | ||
- | nodeSelector: | ||
- | my-role: worker # restrict scheduling to the nodes with the label my-role: worker | ||
- | containers: | ||
- | - name: web | ||
- | image: doritoes/ | ||
- | ports: | ||
- | - containerPort: | ||
- | livenessProbe: | ||
- | httpGet: | ||
- | path: / | ||
- | port: 8080 | ||
- | initialDelaySeconds: | ||
- | periodSeconds: | ||
- | readinessProbe: | ||
- | httpGet: | ||
- | path: / | ||
- | port: 8080 | ||
- | initialDelaySeconds: | ||
- | periodSeconds: | ||
- | </ | ||
- | |||
- | ===== Kick Off the Update ===== | ||
- | Start the update | ||
- | < | ||
- | |||
- | Observe the rollout | ||
- | '' | ||
- | |||
- | Watch the process. | ||
- | < | ||
- | |||
- | After it's done, examine the image that is running. | ||
- | < | ||
- | |||
- | Roll back this update | ||
- | < | ||
- | |||
- | Observe the rollback | ||
- | < | ||
- | What method is used for the rollback? | ||
- | |||
- | View the rollout history | ||
- | < | ||
- | |||
- | Pick a revision number and view the details | ||
- | < | ||
- | |||
- | NOTE on Revision Numbering | ||
- | |||
- | The reason your revision numbers seem out of order could be due to a few factors: | ||
- | * Rollbacks: If you performed rollbacks using kubectl rollout undo, the rolled-back version gets assigned a new, higher revision number. | ||
- | * Manual Manifest Change: Manually editing the deployment' | ||
- | * Failed Deployments: | ||
- | |||
- | ====== Kubernetes Dashboard ====== | ||
- | The Kubernetes Dashboard is a web-based graphical user interface (GUI) built into Kubernetes. See a comprehensive overview of your cluster and perform basic tasks. | ||
- | |||
- | References: | ||
- | * [[https:// | ||
- | |||
- | We will be running this commands on your host system. | ||
- | |||
- | ===== Install ===== | ||
- | Deploy the dashboard | ||
- | < | ||
- | |||
- | ===== Create Service Account ===== | ||
- | Create a service account and bind cluster-admin role to it | ||
- | <code bash> | ||
- | kubectl create serviceaccount dashboard -n kubernetes-dashboard'' | ||
- | kubectl create clusterrolebinding dashboard-admin -n kubernetes-dashboard | ||
- | </ | ||
- | ===== Create Service Account ===== | ||
- | '' | ||
- | |||
- | You will use this token in a moment. | ||
- | |||
- | ===== Launch the Dashboard ===== | ||
- | UI can __only be accessed from the machine where the command is executed__ | ||
- | < | ||
- | |||
- | Browse to: [[http:// | ||
- | |||
- | Authenticate with " | ||
- | |||
- | This is not at full-featured as using kubectl, but simplify things for you. | ||
- | |||
- | Try out deleting pods and watch them get deployed. | ||
- | |||
- | ====== Next Step ====== | ||
- | Continue to [[Review]] | ||
- | |||
- | Or, back to [[Step 5 - Application Pods]] or [[Start]] | ||
- | |||
- | ====== Optional ====== | ||
- | ===== Ramped Slow Rollout ===== | ||
- | This strategy gradually updates pods, ensuring consistent availability, | ||
- | |||
- | **How it works**: New replicas are created while old ones are removed. You directly control the number of pods updated simultaneously. | ||
- | |||
- | **Key difference**: | ||
- | |||
- | Configuration: | ||
- | * maxSurge: 1 Allows only one pod to be added beyond the desired count during the update | ||
- | * maxUnavailable: | ||
- | |||
- | Example: For a 10-pod deployment, this setup guarantees at least 10 pods are always available throughout the update process. | ||
- | |||
- | ===== Best Effort Controlled Rollout ===== | ||
- | This strategy prioritizes update speed over the zero-downtime guarantee of a ramped rollout. It introduces some risk by allowing a configurable percentage of pods to be temporarily unavailable. | ||
- | |||
- | **How it works**: | ||
- | |||
- | **Tradeoff**: | ||
- | |||
- | Configuration: | ||
- | * maxSurge: 0 A Maintains a constant number of pods, optimizing resource usage during the update | ||
- | * maxUnavailable: | ||
- | |||
- | ===== Blue-Green Deployments ===== | ||
- | The purpose of Blue-Green deployments are: | ||
- | * No Downtime: aims to eliminate downtime for updates | ||
- | * Testing in Production: ' | ||
- | * Beyond Simple Rollouts: introduces the idea of traffic management strategies, contrasting it with basic rolling updates | ||
- | |||
- | To do a proper blue-green deployment you need to account for | ||
- | * separate clusters | ||
- | * database mirroring |
lab/kubernetes_app/step_6_-_application_configuration.1707967264.txt.gz · Last modified: 2024/02/15 03:21 by user