Как использовать репозиторий Nexus и Helm для CI / CD

Предполагается, что Helm и Nexus установлены.

Доступ в Helm репозиторий

Сначала скопируйте корневой сертификат с сервера Nexus.

Добавьте репозиторий Nexus в конфигурацию Helm, используя скопированный сертификат:
sudo helm repo add --ca-file ~/ca.crt nexus https://nexus_user:nexus_pass@nexus.domain.ru/repository/helm-hosted/
"nexus" has been added to your repositories

Теперь у вас есть доступ в репозиторий.

Пушинг Helm Chart в Nexus

Чтобы запушить ваш чарт в Nexus, мы сначала его упакуем, а затем загрузим чарт с помощью curl в репозиторий, который мы уже добавили в Helm.

Упаковка чарта:
helm package <папка_с_чартом>

На выходе вы получите запакованный чарт my-chart-0.1.0.tgz.

Отправка чарта в Nexus:
curl --insecure -v -F file=@max-0.1.0.tgz -u nexus_user:nexus_pass https://nexus.domain.ru/service/rest/v1/components?repository=helm-hosted

На выходе вы получите примерно такое сообщение:

* About to connect() to nexus.domain.ru port 443 (#0)
*   Trying 172.24.26.82...
* Connected to nexus.domain.ru (172.24.26.82) port 443 (#0)
* Initializing NSS with certpath: sql:/etc/pki/nssdb
* skipping SSL peer certificate verification
* SSL connection using TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
* Server certificate:
*       subject: CN=*.domain.ru
*       start date: Aug 18 00:00:00 2021 GMT
*       expire date: Aug 18 23:59:59 2022 GMT
*       common name: *.domain.ru
*       issuer: CN=Sectigo RSA Domain Validation Secure Server CA,O=Sectigo Limited,L=Salford,ST=Greater Manchester,C=GB
* Server auth using Basic with user 'rosreestr_pusher'
> POST /service/rest/v1/components?repository=helm-hosted HTTP/1.1
> Authorization: Basic cm9zcmVlc3RyX3B1c2hlcjpuZXh1czRyZnY=
> User-Agent: curl/7.29.0
> Host: nexus.domain.ru
> Accept: */*
> Content-Length: 3953
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=----------------------------c3b97531c3de
>
< HTTP/1.1 100 Continue
< HTTP/1.1 204 No Content
< Server: nginx/1.20.1
< Date: Sun, 10 Oct 2021 14:06:14 GMT
< Connection: keep-alive
< X-Content-Type-Options: nosniff
<
* Connection #0 to host nexus.domain.ru left intact

Убеждаемся, что наш чарт в репозитории:

Установка Helm чарта из Nexus

Чтобы установить Helm чарт из Nexus, вам необходимо обновить индекс репозитория, чтобы были доступны latest пакеты на Nexus, используя  helm repo update, а затем helm install, чтобы создать новый релиз из чарта.

Выполняем:
$ helm repo update
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "gitlab" chart repository
Update Complete. ⎈Happy Helming!⎈

Затем:
$ helm install <имя_чарта> nexusrepo/<имя_чарта_в_репозитории> --version 0.1.0

На выходе получим:
$ sudo helm install max-ko nexus/max --version 0.1.0
NAME: max-ko
LAST DEPLOYED: Sun Oct 10 17:36:31 2021
NAMESPACE: rr
STATUS: deployed
REVISION: 1
NOTES:
1. Get the application URL by running these commands:
  export POD_NAME=$(kubectl get pods --namespace rr -l "app.kubernetes.io/name=max,app.kubernetes.io/instance=max-ko" -o jsonpath="{.items[0].metadata.name}")
  export CONTAINER_PORT=$(kubectl get pod --namespace rr $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
  echo "Visit http://127.0.0.1:8080 to use your application"
  kubectl --namespace rr port-forward $POD_NAME 8080:$CONTAINER_PORT

Ваш чарт установлен и запущен в Kubernetes.

Добавить комментарий