Kubernetes で JFrog Artifactory をセットアップし、Spring Boot アプリケーションを接続する

王林
リリース: 2024-08-22 06:37:32
オリジナル
558 人が閲覧しました

このドキュメントでは、Kubernetes クラスターでの JFrog Artifactory のセットアップに関するガイダンスを提供します。これは、開発者がローカル マシンで実行されている Kubernetes 環境に JFrog をインストールして構成するための基本的なチュートリアルとして機能します。

DevOps リソースを構築するためのローカル環境のセットアップ

Docker コンテナを使用して、複数のアプリケーションの作業環境をセットアップします (セットアップ環境)。このアプローチにより、アプリケーション開発のための完全に分離された保守可能な環境が確保され、これらの環境を簡単に開始および終了できるようになります。以下は、環境を作成するための Docker コマンドです。

docker run -it --name test-jfrog-envornment-box -v ${HOME}/root/ -v ${PWD}/work -w /work --net host developerhelperhub/kub-terr-work-env-box sh
ログイン後にコピー

コンテナには Docker、Kubectl、Helm、Terraform、Kind、Git が含まれています

Kubernetes クラスターでの Jenkins のセットアップ

すべての Terraform スクリプトを作成しました。これらは GitHub リポジトリで入手できます。 Docker コンテナ内でローカルに実行される Kubernetes クラスター上に Jenkins をダウンロードしてセットアップできます。

ローカル Linux マシンにリポジトリのクローンを作成します

git clone https://github.com/developerhelperhub/kuberentes-help.git
cd kuberentes-help/kubenretes/tutorials/sections/0009/
ログイン後にコピー

Kind を使用して Docker コンテナに Kubernetes クラスターをセットアップします。クラスターに「devops-jfrog-cluster-control-plane」という名前を付けます。このクラスターはイングレスをサポートし、サービスへのアクセスを許可するためにポート 80 と 443 を公開します。クラスターの外から。

種類フォルダーでクラスター作成 Terraform スクリプトが利用可能

cd kind
terraform init #Install the required providers to set up the necessary resources.
terraform plan #Verify the resources that will be installed on the system.
terraform apply #Install resources on the system
ログイン後にコピー

次のコマンドはクラスターを確認します

kubectl cluster-info
kubectl get nodes -o wide
ログイン後にコピー

Kubernetes クラスターで Nginx Ingress コントローラーをセットアップします
Kubernetes クラスター内のサービスへの外部アクセスを管理する NGINX Ingress コントローラー。これは、Kubernetes アプリケーションのエントリ ポイントとして機能し、外部 HTTP および HTTPS トラフィックをクラスター内の適切なサービスにルーティングします。

次のコマンドは、クラスターに Ingress コントローラーをインストールします

「ingress」フォルダーで Ingress 作成スクリプトが利用可能

cd ingress
kubectl apply -f ingress-nginx.yaml
ログイン後にコピー

次のコマンドは、nginx Ingress コントローラーを確認します

kubectl get -n ingress-nginx pod
ログイン後にコピー

出力

NAME                                       READY   STATUS      RESTARTS   AGE
ingress-nginx-admission-create-5mt2k       0/1     Completed   0          53s
ingress-nginx-admission-patch-w2rlk        0/1     Completed   0          53s
ingress-nginx-controller-d45d995d4-gl65h   1/1     Running     0          53s
ログイン後にコピー

JFrog Artifactory OSS のセットアップ (オープンソース)

JFrog Artifactory OSS コミュニティ Helm リポジトリを追加します: まず、JFrog Artifactory OSS コミュニティ Helm リポジトリを Helm クライアントに追加する必要があります:

注: JFrog 作成スクリプトは「jfrog」フォルダーで利用できます

helm repo add jfrog https://charts.jfrog.io
helm repo update
ログイン後にコピー

次のコマンドを使用して、クラスターにインストールされているサービスのアプリのバージョンとチャートのバージョンを確認できます:

helm search repo  artifactory-oss
ログイン後にコピー

この例では、カートのバージョンは「107.90.8」、アプリのバージョンは「7.90.8」です

NAME                         CHART VERSION        APP VERSION        DESCRIPTION
jfrog/artifactory-oss        107.90.8             7.90.8             JFrog Artifactory OSS
ログイン後にコピー

helm-value.yaml という名前の Helm 値 YAML ファイルを作成します。これは、JFrog Artifactory OSS サービスの構成に使用されます。この構成ファイルは、クラスターにサービスをインストールするために Helm によって使用されます。

artifactory:
    postgresql:
    postgresqlPassword: postgres_password
    nginx:
    enabled: false
    ingress:
    enabled: false
ログイン後にコピー

上記の構成では、次の点を構成しました:

  • Helm はデフォルトの PostgreSQL データベースを使用しており、データベースのパスワードを指定しました。
  • NGINX および Ingress リソースが無効になっています。

次の Helm コマンドは、クラスターに Artifactory をインストールするために使用されます。 「artifactory-oss」という名前空間を含む必要なリソースをクラスター内に作成し、この名前空間内にすべてのリソースをインストールします。

helm install artifactory-oss -f helm-value.yaml jfrog/artifactory-oss --namespace artifactory-oss --create-namespace
ログイン後にコピー

Helm チャートの値: https://github.com/jfrog/charts/blob/master/stable/artifactory-oss/values.yaml

すべてのリソースが「artifactory-oss」名前空間にインストールされていることを確認できます。 Artifactory サービス UI はポート 8082 で実行されますが、Artifactory 自体はポート 8081 で動作します。

kubectl get -n artifactory-oss all

NAME                               READY   STATUS    RESTARTS   AGE
pod/artifactory-oss-0              0/7     Running   0          3m19s
pod/artifactory-oss-postgresql-0   1/1     Running   0          3m19s

NAME                                          TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)                      AGE
service/artifactory-oss                       ClusterIP   10.96.170.63   <none>        8082/TCP,8025/TCP,8081/TCP   3m19s
service/artifactory-oss-postgresql            ClusterIP   10.96.95.36    <none>        5432/TCP                     3m19s
service/artifactory-oss-postgresql-headless   ClusterIP   None           <none>        5432/TCP                     3m19s

NAME                                          READY   AGE
statefulset.apps/artifactory-oss              0/1     3m19s
statefulset.apps/artifactory-oss-postgresql   1/1     3m19s
ログイン後にコピー

リクエストを Artifactory サービスにルーティングするには、Ingress リソースを作成する必要があります。次の設定を ingress-resource.yaml ファイルに追加します。

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
    name: jfrog-ingress
    namespace: artifactory-oss
    annotations:
    nginx.ingress.kubernetes.io/proxy-body-size: "0"
spec:
    ingressClassName: nginx
    rules:
    - host: jfrog.artifactory.devops.myapp.com
        http:
        paths:
            - path: /
            pathType: ImplementationSpecific
            backend:
                service:
                name: artifactory-oss
                port:
                    number: 8082
ログイン後にコピー

proxy-body-size=0 を設定する必要があります。この設定は、ファイルを Artifactory にアップロードするときにファイル サイズに制限を課さないように Ingress に指示します。

次のコマンドを実行して、クラスターに Ingress を適用します

kubectl apply -f ingress-resource.yaml
ログイン後にコピー

IP アドレスが設定されていることを確認します:

kubectl -n artifactory-oss get ingress

NAME            CLASS   HOSTS                                ADDRESS     PORTS   AGE
jfrog-ingress   nginx   jfrog.artifactory.devops.myapp.com   localhost   80      2m53s
ログイン後にコピー

ローカル マシンの /etc/hosts ファイルの最後にドメインを追加します。この構成は、動作する Linux ボックス「test-jfrog-envornment-box」内に含めるべきではありません。これは個人用マシンの /etc/hosts ファイルに適用する必要があります。
(管理者アクセスが必要になります):

127.0.0.1 jfrog.artifactory.devops.myapp.com
ログイン後にコピー

ブラウザ「http://jfrog.artifactory.devops.myapp.com/」で Artifactory UI を開くことができます

Setup JFrog Artifactory on Kubernetes and Connect Spring Boot Application

You can log in using the default username "admin" and password "password." Upon your first login, Artifactory will prompt you to change the default password. Be sure to update the password, set the base URL to http://jfrog.artifactory.devops.myapp.com (the domain configured in the Artifactory Ingress resource), and skip any other initial configuration steps.

We can create the initial repositories configurations to push the dependencies and binary in the artifactory.

Navigate to “Artifactory → Artifacts → Manage Repositories → Create Repository” and create the following repositories:

  • Local: This repository manages your application binaries. For example “my-app-snapshot”
  • Remote: This repository stores all dependencies used in your application, which will be downloaded from central repositories and stored in repository. For example “my-app-central-snapshot”
  • Virtual: This virtual repository provides a common endpoint that aggregates the “Local” and “Remote” repositories. This endpoint will be configured in your application. “my-app-virtual-snapshot”

I am using maven repository to maintain the repository. Following configuration we have to give “my-app-snapshot” local repository

Setup JFrog Artifactory on Kubernetes and Connect Spring Boot Application

Following configuration we have to give “my-app-central-snapshot” local repository

Setup JFrog Artifactory on Kubernetes and Connect Spring Boot Application

Following configuration we have to give “my-app-virtual-snapshot” local repository

Setup JFrog Artifactory on Kubernetes and Connect Spring Boot Application

Setup JFrog Artifactory on Kubernetes and Connect Spring Boot Application

Add the local and remote repositories to the virtual repository and select the local repository in the “Default Deployment Repository”.

Once all the repositories are created, you can view them in the main section under “Artifactory → Artifacts.” The virtual URL http://jfrog.artifactory.devops.myapp.com/artifactory/my-app-virtual-snapshot/ will be used for your Maven application.

Setup JFrog Artifactory on Kubernetes and Connect Spring Boot Application

We need to configure the authentication details in the Maven settings configuration file “~/.m2/settings.xml” to enable your Maven application to authenticate with Artifactory.

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
    <servers>
        <server>
            <id>my-app-virtual-snapshot</id>
            <username>admin</username>
            <password>Give your artifactory admin passoword</password>
        </server>
    </servers>
</settings>
ログイン後にコピー

Note: The admin user should not be used for UI and Artifactory access. Instead, create a custom user with appropriate permissions for reading and writing in Artifactory.

We have configure the maven repository and distribution management tags inside our maven application POM XML file

<distributionManagement>
    <repository>
        <uniqueVersion>false</uniqueVersion>
        <id>my-app-virtual-snapshot</id>
        <name>my-app-virtual-snapshot</name>
        <url>http://jfrog.artifactory.devops.myapp.com/artifactory/my-app-virtual-snapshot/</url>
        <layout>default</layout>
    </repository>
</distributionManagement>

<repositories>
    <repository>
        <id>my-app-virtual-snapshot</id>
        <name>my-app-virtual-snapshot</name>
        <url>http://jfrog.artifactory.devops.myapp.com/artifactory/my-app-virtual-snapshot/</url>
        <layout>default</layout>
    </repository>
</repositories>
ログイン後にコピー

The we can deploy the maven application with following command

mvn clean deploy
ログイン後にコピー

We can the following output of maven :

Setup JFrog Artifactory on Kubernetes and Connect Spring Boot Application

Refernece Git Repo

  • https://github.com/developerhelperhub/spring-boot-jfrog-artifact-app
  • https://github.com/developerhelperhub/kuberentes-help/tree/main/kubenretes/tutorials/sections/0009

以上がKubernetes で JFrog Artifactory をセットアップし、Spring Boot アプリケーションを接続するの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

ソース:dev.to
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
著者別の最新記事
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!