Прежде чем начать | Before you begin |
Раздел описывает особенности работы Argo CD в поставке с Deckhouse и предполагает наличие базовых знаний или предварительного знакомства с Argo CD. | This section describes how Argo CD works when bundled with Deckhouse and assumes you have basic understanding or prior knowledge of Argo CD. |
Данные, которые используются в примерах ниже:
| The following details are used in the examples below:
|
Концепция | The concept |
Модуль предлагает способ развертывания приложений с помощью связки werf bundle и OCI-based registries. | The module implements a method of deploying applications using a combination of werf bundles and OCI-based registries. |
Преимущество этого подхода заключается в том, что есть единое место доставки артефакта — container registry. Артефакт содержит в себе как образы контейнеров, так и Helm-чарт. Он используется как для первичного деплоя приложения, так и для автообновлений по pull-модели. | The advantage of this approach is that there is a single place to deliver the artifact — the container registry. The artifact contains both container images and the Helm chart. It is used both for the initial deployment of the application and for pull model auto-updates. |
Используемые компоненты: | The following components are used: |
|
|
Чтобы использовать OCI-registry как репозиторий, в параметрах репозитория Argo CD нужно использовать
флаг | To use the OCI registry as a repository, you have to enable the |
Чтобы автоматически обновлять приложения в кластере после доставки артефакта, используется Argo CD Image Updater. В Argo CD Image Updater внесены изменения, позволяющие ему работать с werf-бандлами. | Argo CD Image Updater automatically updates applications in the cluster once the artifact has been delivered. Argo CD Image Updater has been modified to work with werf bundles. |
В примерах используется схема с шаблоном «Application of Applications», подразумевающая два git-репозитория — отдельный репозиторий для приложения и отдельный репозиторий для инфраструктуры: | The examples below use the «Application of Applications» pattern, which implies that there are two git repositories — a dedicated repository for the application, and a dedicated repository for the infrastructure: |
Использование шаблона Application of Applications и отдельного репозитория для инфраструктуры не обязательно, если допускается создавать ресурсы Application вручную. Для простоты в примерах ниже мы будем придерживаться ручного управления ресурсами Application. | The use of the Application of Applications pattern and a separate infrastructure repository is not necessary if you are allowed to create Application resources manually. For the sake of simplicity, in the examples below we will manage Application resources manually. |
Конфигурация с WerfSource CRD | WerfSource CRD-based configuration |
Чтобы использовать Argo CD и Argo CD Image Updater, достаточно настроить объект Application и доступ к registry. Доступ к registry нужен в двух местах — в репозитории Argo CD и в конфигурации Argo CD Image Updater. Для этого нужно сконфигурировать: | All you need to do to use Argo CD and Argo CD Image Updater is to configure the Application object and access to the registry. Access to the registry is required for the Argo CD repository and Argo CD Image Updater. Thus, you have to configure: |
|
|
Модуль | The |
|
|
Таким образом, для деплоя из OCI-репозитория нужно создать три объекта. Все объекты, предполагающие
область видимости namespace, должны быть созданы в namespace | Thus, three objects need to be created for deploying from the OCI repository. Note that all namespaced objects must be created in the |
Пример: | Example: |
yamlapiVersion: deckhouse.io/v1alpha1 kind: WerfSource metadata: name: example spec: imageRepo: cr.example.io/myproject # Репозиторий бандлов и образов. pullSecretName: example-registry # Secret с доступом. — apiVersion: v1 kind: Secret metadata: namespace: d8-delivery # Namespace модуля. name: example-registry type: kubernetes.io/dockerconfigjson # Поддерживается только этот тип Secret’ов. data: .dockerconfigjson: … — apiVersion: argoproj.io/v1alpha1 kind: Application metadata: annotations: argocd-image-updater.argoproj.io/chart-version: ~ 0.0 name: myapp namespace: d8-delivery # Namespace модуля. spec: destination: namespace: myapp server: https://kubernetes.default.svc project: default source: chart: mychart # Бандл — cr.example.com/myproject/mychart. helm: {} repoURL: cr.example.com/myproject # Репозиторий Argo CD из WerfBundle. targetRevision: 1.0.0 syncPolicy: automated: prune: true selfHeal: true syncOptions:
| yamlapiVersion: deckhouse.io/v1alpha1 kind: WerfSource metadata: name: example spec: imageRepo: cr.example.io/myproject # bundle and image repository pullSecretName: example-registry # Secret with the credentials required for access — apiVersion: v1 kind: Secret metadata: namespace: d8-delivery # namespace of the module name: example-registry type: kubernetes.io/dockerconfigjson # only this Secret type is supported data: .dockerconfigjson: … — apiVersion: argoproj.io/v1alpha1 kind: Application metadata: annotations: argocd-image-updater.argoproj.io/chart-version: ~ 0.0 name: myapp namespace: d8-delivery # namespace of the module spec: destination: namespace: myapp server: https://kubernetes.default.svc project: default source: chart: mychart # bundle — cr.example.com/myproject/mychart helm: {} repoURL: cr.example.com/myproject # Argo CD repository from WerfBundle targetRevision: 1.0.0 syncPolicy: automated: prune: true selfHeal: true syncOptions:
|
Публикация артефакта в registry | Publishing an artifact to the registry |
OCI-чарт Helm требует, чтобы имя чарта в | The Helm OCI chart requires that the chart name in |
sh werf bundle publish –repo cr.example.com/myproject/mychart –tag 1.0.0 | sh werf bundle publish –repo cr.example.com/myproject/mychart –tag 1.0.0 |
Подробнее о бандлах — в документации werf. | For more information about bundles, see the werf documentation. |
Автообновление бандла | Bundle auto-updating |
Argo CD Image Updater используется для автоматического обновления Application из опубликованного
werf-бандла в pull-модели. Image Updater сканирует OCI-репозиторий с заданным интервалом и обновляет
| As part of the pull model, Argo CD Image Updater automatically updates the Application using a published werf bundle. Image Updater scans the OCI repository at set intervals and updates |
Правила обновлений образов | The rules for updating images |
В Application нужно добавить аннотацию с правилами обновления образа (подробнее — в документации werf). | You have to add an annotation to the Application object containing the rules governing image updates (see the werf documentation for details). |
Пример правила, обновляющего патч-версии приложения ( | Here is an example of a rule that updates a patch version of an application ( |
yaml apiVersion: argoproj.io/v1alpha1 kind: Application metadata: annotations: argocd-image-updater.argoproj.io/chart-version: ~ 1.0 | yaml apiVersion: argoproj.io/v1alpha1 kind: Application metadata: annotations: argocd-image-updater.argoproj.io/chart-version: ~ 1.0 |
Настройки доступа к registry | Access settings for the registry |
У сервис-аккаунта | The |
Индивидуальная настройка для Application | Per-Application configuration |
Сослаться на параметры доступа можно индивидуально в каждом Application с помощью аннотации | You can refer access credentials individually in each Application using the |
Пример: | Example: |
yaml apiVersion: argoproj.io/v1alpha1 kind: Application metadata: annotations: argocd-image-updater.argoproj.io/chart-version: ~ 1.0 argocd-image-updater.argoproj.io/pull-secret: pullsecret:d8-delivery/example-registry | yaml apiVersion: argoproj.io/v1alpha1 kind: Application metadata: annotations: argocd-image-updater.argoproj.io/chart-version: ~ 1.0 argocd-image-updater.argoproj.io/pull-secret: pullsecret:d8-delivery/example-registry |
Особенности аутентификации командной утилиты
| How to authenticate using the
|
Пользователь Argo CD | Argo CD user |
Задайте | Set |
Чтобы включить пользователя | To do so: |
|
|
sh kubectl edit mc delivery | sh kubectl edit mc delivery |
|
|
yaml apiVersion: deckhouse.io/v1alpha1 kind: ModuleConfig metadata: name: delivery (…) spec: enabled: true settings: argocd: admin: enabled: true version: 1 | yaml apiVersion: deckhouse.io/v1alpha1 kind: ModuleConfig metadata: name: delivery (…) spec: enabled: true settings: argocd: admin: enabled: true version: 1 |
kubectl | kubectl |
Если настроен внешний доступ к Kubernetes API, | If external access to Kubernetes API is configured, |
sh argocd login argocd.example.com –core | sh argocd login argocd.example.com –core |
Утилита | The |
Выполните следующую команду для выбора namespace | Use the following command to set |
sh kubectl config set-context –current –namespace=d8-delivery | sh kubectl config set-context –current –namespace=d8-delivery |
Dex | Dex |
Авторизация через Dex не работает для CLI, но работает в веб-интерфейсе. | The Dex-based authorization does not work for the CLI, but it does in the web interface. |
Вот так не работает, потому нет возможности зарегистрировать публичного клиента для DexClient, в роли которого выступает Argo CD: | That is, you cannot authorize via SSO because Dex Client in Deckhouse does not support public clients, in this case Argo CD: |
sh argocd login argocd.example.com –sso | sh argocd login argocd.example.com –sso |
Частичное использование WerfSource CRD | Partial WerfSource CRD usage scenarios |
Без репозитория Argo CD | No Argo CD repository |
WerfSource отвечает за создание репозитория в Argo CD и внесение registry в конфигурацию
Image Updater. От создания репозитория можно отказаться в WerfSource, для этого нужно установить
параметр | WerfSource creates a repository on the Argo CD and adds registry information to the Image Updater configuration. However, it also allows you to skip the repository creation. To do so, set the |
yamlapiVersion: deckhouse.io/v1alpha1 kind: WerfSource metadata: name: example spec: … argocdRepoEnabled: false | yamlapiVersion: deckhouse.io/v1alpha1 kind: WerfSource metadata: name: example spec: … argocdRepoEnabled: false |
Как самостоятельно создать репозиторий Argo CD для OCI-registry | How to manually create an Argo CD repository for the OCI registry |
Registry играет роль репозитория бандлов. Чтобы это работало, нужно в репозитории включить режим
OCI. Однако веб-интерфейс не позволяет установить флаг | The registry acts as a repository for the bundles. To use it, you will have to enable OCI mode in the repository. Unfortunately, the web interface does not allow you to set the |
Argo CD CLI | Using the Argo CD CLI |
Утилита | The |
sh
$ argocd repo add cr.example.com/myproject | sh
$ argocd repo add cr.example.com/myproject |
Веб-интерфейс и kubectl | Using the web interface and kubectl |
В существующий репозиторий недостающий флаг можно добавить вручную: | The missing flag can be added manually to an existing repository: |
sh kubectl -n d8-delivery edit secret repo-…. | sh kubectl -n d8-delivery edit secret repo-…. |
yaml apiVersion: v1 kind: Secret stringData: # <—– Добавить enableOCI: “true” # <—– и сохранить. data: (…) metadata: (…) name: repo-…. namespace: d8-delivery type: Opaque | yaml apiVersion: v1 kind: Secret stringData: # <—– add enableOCI: “true” # <—– and save data: (…) metadata: (…) name: repo-…. namespace: d8-delivery type: Opaque |
Без registry для Image Updater | No registry for Image Updater |
Registry в | The registries in |
yaml apiVersion: argoproj.io/v1alpha1 kind: Application metadata: annotations: argocd-image-updater.argoproj.io/chart-version: ~ 1.0 argocd-image-updater.argoproj.io/pull-secret: pullsecret:d8-delivery/example-registry | yaml apiVersion: argoproj.io/v1alpha1 kind: Application metadata: annotations: argocd-image-updater.argoproj.io/chart-version: ~ 1.0 argocd-image-updater.argoproj.io/pull-secret: pullsecret:d8-delivery/example-registry |