Skip to main content

[TIL] Argo Rollouts có nút bấm restart trên giao diện ArgoCD

Argo CD là gì

Argo CD is a declarative, GitOps continuous delivery tool for Kubernetes. https://argoproj.github.io/cd/

Argo CD và FluxCD là 2 lựa chọn phổ biến để thực hiện "Continuous Delivery" (CD) trên Kubernetes. Argo CD có giao diện nên thường được ưa chuộng hơn.

Argo Rollouts là gì

Argo Rollouts is a Kubernetes controller and set of CRDs which provide advanced deployment capabilities such as blue-green, canary, canary analysis, experimentation, and progressive delivery features to Kubernetes. https://argoproj.github.io/argo-rollouts/

Kubernetes Deployment mặc định hỗ trợ strategy deploy RollingUpdate, nhưng chiến thuật này có nhiều hạn chế. Argo Rollouts hỗ trợ nhiều chiến thuật deploy như blue-green, canary với nhiều tính năng phức tạp hơn.

Restart rollout

Khi cần restart các pod trong 1 rollout, các cách làm:

  • xóa từng pod đi để replicaset sẽ tạo lại pod mới (không khả thi với số lượng pod lớn, bấm mỏi tay)
  • xóa replicaset đi để rollout tạo lại replicaset mới
  • restart rollout: đây là 1 tính năng của Argo Rollouts, nó thậm chí có cả 1 nút bấm trong menu của rollout object trên giao diện Argo UI. https://argoproj.github.io/argo-rollouts/features/restart/#how-it-works

How it works

During a restart, the controller iterates through each ReplicaSet to see if all the Pods have a creation timestamp which is newer than the restartAt time. For every pod older than the restartAt timestamp, the Pod will be evicted, allowing the ReplicaSet to replace the pod with a recreated one.

Code:

func (p *RolloutPodRestarter) Reconcile(roCtx *rolloutContext) error {
  ...
    restartedAt := roCtx.rollout.Spec.RestartAt
    needsRestart := 0
    restarted := 0
    for _, pod := range rolloutPods {
        if pod.CreationTimestamp.After(restartedAt.Time) || pod.CreationTimestamp.Equal(restartedAt) {
            continue
        }
        needsRestart += 1
        if canRestart <= 0 {
            continue
        }
        if pod.DeletionTimestamp != nil {
            continue
        }
        newLogCtx := logCtx.WithField("Pod", pod.Name).WithField("CreatedAt", pod.CreationTimestamp.Format(time.RFC3339)).WithField("RestartAt", restartedAt.Format(time.RFC3339))
        newLogCtx.Info("restarting Pod that's older than restartAt Time")
        evictTarget := policy.Eviction{
            ObjectMeta: metav1.ObjectMeta{
                Name:      pod.Name,
                Namespace: pod.Namespace,
            },
        }
        err := p.client.CoreV1().Pods(pod.Namespace).Evict(ctx, &evictTarget)
    ...

github.com/argoproj/argo-rollouts

Kết luận

Tính năng nhiều khi có ở đó, nhưng không dễ phát hiện ra, người dùng thường làm theo "bản năng" thay vì đọc doc.

Hết.

HVN at https://pymi.vn and https://www.familug.org.

Ủng hộ tác giả 🍺

Comments

Popular posts from this blog

Tài liệu và hướng dẫn học Python

Để tiết kiệm thời gian, tốt nhất là đi học PyMI Updated: 130617 Sau đây là các tài liệu khuyên dùng: Vì nhiều lý do, nên học python2.7 tại thời điểm hiện tại (giờ là tháng 6/2013 - muốn biết tại sao thì tự tìm hiểu) python 3.5+ (giờ là tháng 2/2017) Chuẩn bị: 1. biết bật tắt máy 2. biết cài python 3. tập gõ 10 ngón - gõ 2 ngón hay 1 ngón cũng không sao, nhưng 10 ngón là cách dễ nhất để gõ nhanh nhất. Tài liệu - Nên dùng tài liệu tại trang chủ của Python làm chính, tham khảo thêm các tài liệu khác tại http://www.familug.org/2016/12/free-ebook.html Căn bản, mới học 1.1 Python PyMI.vn https://pymi.vn/tutorial/ 1.2. Python offical tutorial kết hợp làm bài tập trên HackerRank  (đề bài bằng tiếng Anh, nhưng Google translate 1 lúc cũng ra vì có nhiều ví dụ mẫu đi kèm). Học viên của Pymi.vn có rất nhiều học viên đã tự học với Learn Python the hard way nhưng chưa thấy ai thành công cả. Hai link dưới nên đọc sau khi đã nắm được những phần cơ bản của ngôn ngữ pytho...

The PyMiers

New FAMILUG