Friday, November 15, 2024
GCP Kubernetes

Managing Deployments Using Kubernetes Engine

using

“Managing Deployments Using Kubernetes Engine”

Pengantar

Praktik Dev Ops akan secara teratur menggunakan beberapa penerapan untuk mengelola skenario penerapan aplikasi seperti “Penerapan Berkelanjutan”, “Penempatan Biru-Hijau”, “Penempatan Canary” dan banyak lagi. Lab ini memberikan latihan dalam penskalaan dan pengelolaan container sehingga Anda dapat menyelesaikan skenario umum ini di mana beberapa penerapan heterogen digunakan.

Set zone

gcloud config set compute/zone us-central1-a

Get Contoh Code

gsutil -m cp -r gs://spls/gsp053/orchestrate-with-kubernetes .
cd orchestrate-with-kubernetes/kubernetes
gcloud container clusters create bootcamp --num-nodes 5 --scopes "https://www.googleapis.com/auth/projecthosting,storage-rw"

Deployment object

kubectl explain deployment
kubectl explain deployment --recursive
kubectl explain deployment.metadata.name

Buat deployment

nano deployments/auth.yaml

Edit bagian image

...
containers:
- name: auth
  image: "kelseyhightower/auth:1.0.0"
...
  • Buat deployment
kubectl create -f deployments/auth.yaml
kubectl get deployments
  • Buat Replica
kubectl get replicasets
  • Cek pod
kubectl get pods
  • Buat Service
kubectl create -f services/auth.yaml
  • Buat hello deployment
kubectl create -f deployments/hello.yaml
kubectl create -f services/hello.yaml
  • Buat frontend
kubectl create secret generic tls-certs --from-file tls/
kubectl create configmap nginx-frontend-conf --from-file=nginx/frontend.conf
kubectl create -f deployments/frontend.yaml
kubectl create -f services/frontend.yaml
  • cek service frontend
kubectl get services frontend

Scale Deployment

  • Explain
kubectl explain deployment.spec.replicas
  • replica
kubectl scale deployment hello --replicas=5
  • Cek pod
kubectl get pods | grep hello- | wc -l
  • Scale lagi
kubectl scale deployment hello --replicas=3
  • Cek lagi pod nya
kubectl get pods | grep hello- | wc -l

Rolling update

  • Edit Deployment
kubectl edit deployment hello

Ganti bagian image

...
containers:
  image: kelseyhightower/hello:2.0.0
...
  • buat replica
kubectl get replicaset
  • Cek history
kubectl rollout history deployment/hello

Pause rolling update

  • pause
kubectl rollout pause deployment/hello
  • Cek state
kubectl rollout status deployment/hello
kubectl get pods -o jsonpath --template='{range .items[*]}{.metadata.name}{"\t"}{"\t"}{.spec.containers[0].image}{"\n"}{end}'

Resume rolling update

  • Resume
kubectl rollout resume deployment/hello
  • Cek status
kubectl rollout status deployment/hello

Rollback update

  • Rollout
kubectl rollout undo deployment/hello
  • Cek History
kubectl rollout history deployment/hello
kubectl get pods -o jsonpath --template='{range .items[*]}{.metadata.name}{"\t"}{"\t"}{.spec.containers[0].image}{"\n"}{end}'

Canary deployments

  • Buat Canary Deployment
kubectl create -f deployments/hello-canary.yaml
  • Cek deployment
kubectl get deployments
  • Cek hello
curl -ks https://`kubectl get svc frontend -o=jsonpath="{.status.loadBalancer.ingress[0].ip}"`/version

Blue-green deployments

  • Update service
kubectl apply -f services/hello-blue.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-green
spec:
  replicas: 3
  selector:
    matchLabels:
      app: hello
  template:
    metadata:
      labels:
        app: hello
        track: stable
        version: 2.0.0
    spec:
      containers:
        - name: hello
          image: kelseyhightower/hello:2.0.0
          ports:
            - name: http
              containerPort: 80
            - name: health
              containerPort: 81
          resources:
            limits:
              cpu: 0.2
              memory: 10Mi
          livenessProbe:
            httpGet:
              path: /healthz
              port: 81
              scheme: HTTP
            initialDelaySeconds: 5
            periodSeconds: 15
            timeoutSeconds: 5
          readinessProbe:
            httpGet:
              path: /readiness
              port: 81
              scheme: HTTP
            initialDelaySeconds: 5
            timeoutSeconds: 1
  • Buat green deployment
kubectl create -f deployments/hello-green.yaml
  • Update service
kubectl apply -f services/hello-green.yaml
  • Cek status
curl -ks https://`kubectl get svc frontend -o=jsonpath="{.status.loadBalancer.ingress[0].ip}"`/version

Blue-Green Rollback

  • Update service
kubectl apply -f services/hello-blue.yaml
  • cek status
curl -ks https://`kubectl get svc frontend -o=jsonpath="{.status.loadBalancer.ingress[0].ip}"`/version

Penutup

Sahabat Blog Learning & Doing demikianlah penjelasan mengenai Managing Deployments Using Kubernetes Engine . Semoga Bermanfaat . Sampai ketemu lagi di postingan berikut nya.

(Visited 165 times, 1 visits today)

Similar Posts