> Java > java지도 시간 > 본문

Kubernetes에서 JFrog Artifactory 설정 및 Spring Boot 애플리케이션 연결

王林
풀어 주다: 2024-08-22 06:37:32
원래의
558명이 탐색했습니다.

이 문서는 Kubernetes 클러스터에서 JFrog Artifactory를 설정하는 방법에 대한 지침을 제공합니다. 이는 개발자가 로컬 시스템에서 실행되는 Kubernetes 환경에 JFrog를 설치하고 구성하기 위한 기본 튜토리얼 역할을 합니다.

DevOps 리소스 구축을 위한 로컬 환경 설정

저는 Docker 컨테이너를 사용하여 여러 애플리케이션에 대한 작업 환경(Setup Environment)을 설정합니다. 이 접근 방식은 애플리케이션 개발을 위한 완전히 격리되고 유지 관리 가능한 환경을 보장하므로 이러한 환경을 쉽게 시작하고 종료할 수 있습니다. 아래는 환경을 생성하는 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 설정

GitHub 저장소에서 사용할 수 있는 모든 Terraform 스크립트를 만들었습니다. 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 수신 컨트롤러 설정
Kubernetes 클러스터의 서비스에 대한 외부 액세스를 관리하는 NGINX 수신 컨트롤러. 이는 외부 HTTP 및 HTTPS 트래픽을 클러스터 내의 적절한 서비스로 라우팅하는 Kubernetes 애플리케이션의 진입점 역할을 합니다.

다음 명령을 사용하여 클러스터에 수신 컨트롤러를 설치합니다

“ingress” 폴더에서 사용 가능한 Ingress 생성 스크립트

cd ingress
kubectl apply -f ingress-nginx.yaml
로그인 후 복사

다음 명령으로 nginx 수신 컨트롤러를 확인하세요

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
로그인 후 복사

JFrog Artifactory OSS 서비스를 구성하는 데 사용할 helm-value.yaml이라는 Helm 값 YAML 파일을 만듭니다. 이 구성 파일은 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을 구성해야 합니다. 이 설정은 Ingress가 Artifactory에 파일을 업로드할 때 파일 크기에 제한을 두지 않도록 지시합니다.

클러스터에 인그레스를 적용하려면 다음 명령을 실행하세요

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/”에서 아티팩트 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 중국어 웹사이트의 기타 관련 기사를 참조하세요!

원천:dev.to
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!