k8s インストール nexus3 プライベートサーバー

1. 環境整備

1.1 環境の説明

この記事では、WMware 仮想マシン、オペレーティング システム CentOS 8 に基づいて MongoDB を構築し、Kubeadm に基づいて k8s クラスターを構築しました。k8s ノード情報は次のとおりです。

サーバ IPアドレス
マスター 192.168.31.80
ノード1 192.168.31.8
ノード2 192.168.31.9

k8s クラスターの構築方法を知りたい場合は、私の記事「kubeadm による k8s クラスターのデプロイ」にアクセスして参照してください。

1.2 インストール手順

エンタープライズレベルのアプリケーションの増加と要件の増大に伴い、開発者はアーティファクトを保存および共有するための信頼性が高く、スケーラブルで管理しやすいリポジトリをますます必要としています。Nexus は人気のあるリポジトリ マネージャーであり、アーティファクトを管理および配布するためのオープン ソースの Java ベース ソフトウェアです。Nexus 3 は、多くの新機能と改善を提供する Nexus の新しいバージョンで、さらに強力で柔軟なリポジトリ マネージャーになります。この記事では、k8s に Nexus 3 プライベートサーバーを導入する方法を詳しく紹介します。

2.NFSをインストールする

NFS ストレージの主な機能は、安定したバックエンド ストレージを提供することであり、Nexus ポッドに障害が発生した場合、再起動または移行された場合でも、元のデータを引き続き取得できます。

2.1 NFS のインストール

マスター ノードに NFS ストレージを作成することを選択し、最初に次のコマンドを実行して NFS をインストールします。

yum -y install  nfs-utils rpcbind

2.2 NFS共有フォルダーの作成

cd /var/nfs/

mkdir nexus

 2.3 NFS サービスを再起動する

systemctl start nfs-server
systemctl enabled nfs-server
systemctl start rpcbind
systemctl enabled rpcbind

2.4 NFS クライアント SA 認証の作成

  #创建namespace
kubectl create ns nexus

cat > nexus-nfs-client-sa.yaml

apiVersion: v1
kind: ServiceAccount
metadata:
  name: nfs-client
  namespace: nexus
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: nfs-client-runner
  namespace: nexus
rules:
  - apiGroups: [""]
    resources: ["persistentvolumes"]
    verbs: ["get","list","watch","create","delete"]
  - apiGroups: [""]
    resources: ["persistentvolumeclaims"]
    verbs: ["get","list","watch","create","delete"]
  - apiGroups: ["storage.k8s.io"]
    resources: ["storageclasses"]
    verbs: ["get","list","watch"]
  - apiGroups: [""]
    resources: ["events"]
    verbs: ["get","list","watch","create","update","patch"]
  - apiGroups: [""]
    resources: ["endpoints"]
    verbs: ["create","delete","get","list","watch","patch","update"]

---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: run-nfs-provisioner
  namespace: nexus
subjects:
  - kind: ServiceAccount
    name: nfs-client
    namespace: nexus
roleRef:
  kind: ClusterRole
  name: nfs-client-runner
  apiGroup: rbac.authorization.k8s.io

2.5 作成コマンドの実行

kubectl apply  -f nexus-nfs-client-sa.yaml

2.6 サービスが成功したかどうかを確認する

kubectl get ServiceAccount -n nexus -o wide

kubectl get ClusterRole -n nexus -o wide

kubectl get ClusterRoleBinding -n nexus -o wide

2.7 NFSクライアントの作成

cat > nexus-nfs-client.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nfs-client
  labels:
    app: nfs-client
  # replace with namespace where provisioner is deployed
  namespace: nexus
spec:
  replicas: 1
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: nfs-client
  template:
    metadata:
      labels:
        app: nfs-client
    spec:
      serviceAccountName: nfs-client
      containers:
        - name: nfs-client
          image: quay.io/external_storage/nfs-client-provisioner:latest
          volumeMounts:
            - name: nfs-client-root
              mountPath: /persistentvolumes
          env:
            - name: PROVISIONER_NAME   ## 这个名字必须与storegeclass里面的名字一致
              value:  my-nexus-nfs
            - name: ENABLE_LEADER_ELECTION  ## 设置高可用允许选举,如果replicas参数等于1,可不用
              value: "True"
            - name: NFS_SERVER
              value: 192.168.31.80  #修改为自己的ip(部署nfs的机器ip)
            - name: NFS_PATH
              value: /var/nfs/nexus     #修改为自己的nfs安装目录
      volumes:
        - name: nfs-client-root
          nfs:
            server: 192.168.31.80 #修改为自己的ip(部署nfs的机器ip)
            path: /var/nfs/nexus     #修改为自己的nfs安装目录

2.8 ストアクラスの作成

cat > nexus-store-class.yaml


apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: nexus-nfs-storage
  namespace: nexus
provisioner: my-nexus-nfs

2.9 NFS クライアントとストアクラスが正常に作成されたかどうかを確認する

kubectl get StorageClass -n nexus -o wide

kubectl get pod -n nexus -o wide


 3. PVボリュームの作成

3.1 PVボリュームyamlの作成

cat > nexus-pv.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nexus-pvc # 自定义
  namespace: nexus # 自定义,与本文前后所有命名空间保持一致
  labels:
    pvc: nexus-pvc # 自定义
spec:
  storageClassName: nexus-nfs-storage # 创建的StorageClass的名字
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 20Gi  

3.2 コマンド作成の実行

kubectl apply  -f nexus-pv.yaml

3.3 PVボリュームが正常に作成されたか確認する

kubectl get pv

 4.Nexus のデプロイ

4.1 サービスの作成

cat > nexus-service.yaml

kind: Service
apiVersion: v1
metadata:
  name: nexus3
  namespace: nexus
  labels:
    app: nexus3
spec:
  type: NodePort
  ports:
    - port: 8081
      targetPort: 8081
      nodePort: 30520 # 对外开发的端口,自定义
  selector:
    app: nexus3

4.2 コマンド作成の実行

kubectl apply -f nexus-service.yaml

4.3 デプロイメントの作成

cat > nexus-deployment.yaml

kind: Deployment
apiVersion: apps/v1
metadata:
  name: nexus3 # 自定义
  labels:
    app: nexus3 # 自定义
  namespace: nexus # 自定义,与本文前后所有命名空间保持一致
spec:
  replicas: 1 # 副本的数量
  selector:
    matchLabels:
      app: nexus3
  template:
    metadata:
      labels:
        app: nexus3
    spec:
      containers:
        - name: nexus3
          image: sonatype/nexus3
          ports:
            - name: nexus3-8081
              containerPort: 8081 # 容器端口
              protocol: TCP
          resources:
            limits:
              memory: 6G
              cpu: 1000m
          imagePullPolicy: IfNotPresent
          volumeMounts:
          - name: data
            mountPath: /nexus-data # 数据路径挂载出来
      restartPolicy: Always
      volumes:
        - name: data
          persistentVolumeClaim:
            claimName: nexus-pvc # PVC的名字
            readOnly: false

4.4 コマンドを実行してデプロイメントを作成する

kubectl apply -f nexus-deployment.yaml

4.5 サービスとデプロイメントが正常に作成されたかどうかを確認する

kubectl get service -n nexus -o wide

kubectl get pod -n nexus -o wide

 

 

 

 5、ログインテスト

5.1 Nexus への外部ネットワーク アクセスをテストする

ようこそ - Nexus リポジトリ マネージャー

 5.2 デフォルトのログインパスワードを取得する

Nexus コンテナに入ります。デフォルトのログイン パスワードは /nexus-data/admin.password ディレクトリにあります。cat /nexus-data/admin.password によってパスワードを画面に出力します。デフォルトのアカウント名は admin です。

 5.3 パスワードの変更

 パスワード変更後、再度ログインしてください。これで、k8s を介した Nexus の展開が完了しました。

この記事が参考になったと思ったら、いいね+ブックマーク+フォローをお願いします!

おすすめ

転載: blog.csdn.net/qq_25409421/article/details/131382138