UncleNUC Wiki

Second chance for NUCs

User Tools

Site Tools


lab:kubernetes_app:step_6_-_application_configuration

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
lab:kubernetes_app:step_6_-_application_configuration [2024/02/15 01:23] – [Troubleshooting] userlab:kubernetes_app:step_6_-_application_configuration [2024/05/13 18:16] (current) – removed user
Line 1: Line 1:
-====== Step 6 - Application Configuration ====== 
-// See [[https://spot.io/resources/kubernetes-autoscaling/5-kubernetes-deployment-strategies-roll-out-like-the-pros/]] // 
  
-In this step we look at deploying different application images 
-  * doritoes/k8s-php-demo-app:blue 
-  * doritoes/k8s-php-demo-app:green 
-  * doritoes/k8s-php-demo-app:orange 
- 
-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 
-Strategies that requires customization or specialized tools: 
-  * ramped slow rollout 
-  * best-effort controlled rollout 
-  * 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 
-<code>watch -d -n 1 'kubectl get pods,deploy'</code> 
-You will watch the status of your deployment here. 
- 
-===== Update the Image in k8s-deployment-web.yml ===== 
-Update ''k8s-deployment-web.yml'' to use the new image tag 
-<code>image: doritoes/k8s-php-demo-app:green</code> 
- 
-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/k8s-php-demo-app:green 
-        ports: 
-        - containerPort: 8080 
-        livenessProbe: 
-          httpGet: 
-            path: /liveness.php 
-            port: 8080 
-          initialDelaySeconds: 30 
-          periodSeconds: 10 
-        readinessProbe: # Add the readinessProbe section 
-          httpGet: 
-            path: /readiness.php 
-            port: 8080 
-          initialDelaySeconds: 5 
-          periodSeconds: 5 
-</file> 
- 
-===== 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 
-<code>kubectl apply -f k8s-deployment-web.yml</code> 
- 
-Observe the rollout 
-<code>kubectl rollout status deployment/web-deployment</code> 
- 
-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: 
-<code>kubectl describe deployment/web-deployment</code> 
- 
-Here is a way to get the images running on all pods: 
-<code> 
-kubectl get pods --all-namespaces -o jsonpath='{range .items[*]}{"\n"}{.metadata.name}{":\t"}{range .spec.containers[*]}{.image}{", "}{end}{end}' |\ 
-sort 
-</code> 
-===== 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: 
-<code> 
-kubectl describe deployment web-deployment 
-kubectl get pods 
-kubectl logs <pod-name> 
-</code> 
- 
-===== Rollback ===== 
-Roll back the update using 
-<code> 
-kubectl rollout undo deployment/web-deployment  
-</code> 
- 
- 
-Observe the rollback 
-<code>kubectl rollout status deployment/web-deployment</code> 
- 
-Watch the status in the other session. 
- 
-===== Improvements ===== 
-You can customize the rolling deployment behavior within your Deployment spec with the ''maxSurge'' and ''maxUnavailable'' properties. 
- 
-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: 0  # No downtime during the update  
-  # ... rest of your deployment specification ... 
- </code> 
- 
-====== Next Step ====== 
-Continue to [[Step 7 - Load Balancing]] 
- 
-Or, back to [[Step 5 - Application Pods]] or [[Start]] 
lab/kubernetes_app/step_6_-_application_configuration.1707960239.txt.gz · Last modified: 2024/02/15 01:23 by user