Site icon Learning & Doing

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"
...
kubectl create -f deployments/auth.yaml
kubectl get deployments
kubectl get replicasets
kubectl get pods
kubectl create -f services/auth.yaml
kubectl create -f deployments/hello.yaml
kubectl create -f services/hello.yaml
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
kubectl get services frontend

Scale Deployment

kubectl explain deployment.spec.replicas
kubectl scale deployment hello --replicas=5
kubectl get pods | grep hello- | wc -l
kubectl scale deployment hello --replicas=3
kubectl get pods | grep hello- | wc -l

Rolling update

kubectl edit deployment hello

Ganti bagian image

...
containers:
  image: kelseyhightower/hello:2.0.0
...
kubectl get replicaset
kubectl rollout history deployment/hello

Pause rolling update

kubectl rollout pause deployment/hello
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

kubectl rollout resume deployment/hello
kubectl rollout status deployment/hello

Rollback update

kubectl rollout undo deployment/hello
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

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

Blue-green deployments

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
kubectl create -f deployments/hello-green.yaml
kubectl apply -f services/hello-green.yaml
curl -ks https://`kubectl get svc frontend -o=jsonpath="{.status.loadBalancer.ingress[0].ip}"`/version

Blue-Green Rollback

kubectl apply -f services/hello-blue.yaml
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.

Exit mobile version