• 云原生Kubernetes: K8S 1.29版本 部署Nexus


    目录

     一、实验

    1.环境

    2.搭建NFS

    3. K8S 1.29版本 部署Nexus

    二、问题

    1.volumeMode有哪几种模式


     一、实验

    1.环境

    (1)主机

    表1 主机

    主机架构版本IP备注
    masterK8S master节点1.29.0192.168.204.8

    node1K8S node节点1.29.0192.168.204.9
    node2K8S node节点1.29.0192.168.204.10已部署Kuboard

    (2)master节点查看集群

    1. 1)查看node
    2. kubectl get node
    3. 2)查看node详细信息
    4. kubectl get node -o wide

    (3)查看pod

    [root@master ~]# kubectl get pod -A
    

    (4) 访问Kuboard

    http://192.168.204.10:30080/kuboard/cluster

    查看节点

    2.搭建NFS

    (1)检查并安装rpcbind和nfs-utils软件包

    [root@master ~]# rpm -q rpcbind nfs-utils
    

    (2)创建目录并授权

    [root@master ~]# mkdir -p /opt/nexus
    

    [root@master opt]# chmod 777 nexus/
    

    (3)打开nfs的配置文件

    [root@master opt]# vim /etc/exports
    

    (4)配置文件

    给所有网段用户赋予读写权限、同步内容、不压缩共享对象root用户权限

    1. ……
    2. /opt/nexus *(rw,sync,no_root_squash)

    (5)先后开启rpcbind、nfs服务并热加载配置文件内容,查看本机发布的nfs共享目录

    [root@master opt]# systemctl restart nfs
    

    (6)监听端口

    [root@master opt]# ss -antp | grep rpcbind
    

    (7)查看共享

    [root@master opt]# showmount -e
    

    其他节点查看

    [root@node1 ~]# showmount -e master
    

    3. K8S 1.29版本 部署Nexus

    (1)创建名称空间

    [root@master opt]# kubectl create ns nexus
    

    (2)创建nexus的pv

    [root@master ~]# vim pv-nexus.yaml
    

    1. apiVersion: v1
    2. kind: PersistentVolume
    3. metadata:
    4. name: pv-nexus
    5. spec:
    6. capacity:
    7. storage: 30Gi #配置容量大小
    8. volumeMode: Filesystem
    9. accessModes:
    10. - ReadWriteOnce #配置访问策略为只允许一个节点读写
    11. persistentVolumeReclaimPolicy: Retain #配置回收策略,Retain为手动回收
    12. storageClassName: "pv-nexus" #配置为nfs
    13. nfs:
    14. path: /opt/nexus #配置nfs服务端的共享路径
    15. server: 192.168.204.8 #配置nfs服务器地址

    (3)生成资源

    [root@master ~]# kubectl apply -f pv-nexus.yaml 
    

    (4)查看pv

    [root@master ~]# kubectl get pv
    

    (5)拉取镜像

     node1

    [root@node1 ~]# docker pull sonatype/nexus3:3.28.0
    

    (6) 导出镜像

    [root@node1 ~]# docker save -o nexus.tar sonatype/nexus3:3.28.0
    

    (7)复制Docker镜像到node2节点

    [root@node1 ~]# scp nexus.tar root@node2:~
    

    (8)node2节点导入Docker镜像

    [root@node2 ~]# docker load -i nexus.tar 
    

    (9)部署nexus

    [root@master ~]# vim nexus.yaml
    

    1. apiVersion: v1
    2. kind: PersistentVolumeClaim
    3. metadata:
    4. name: nexus-pvc
    5. namespace: nexus
    6. spec:
    7. accessModes:
    8. - ReadWriteOnce
    9. storageClassName: "pv-nexus"
    10. resources:
    11. requests:
    12. storage: 30Gi
    13. ---
    14. apiVersion: apps/v1
    15. kind: Deployment
    16. metadata:
    17. labels:
    18. app: nexus
    19. name: nexus
    20. namespace: nexus
    21. spec:
    22. replicas: 1
    23. progressDeadlineSeconds: 600
    24. minReadySeconds: 30
    25. strategy:
    26. rollingUpdate:
    27. maxSurge: 1
    28. maxUnavailable: 0
    29. type: RollingUpdate
    30. selector:
    31. matchLabels:
    32. app: nexus
    33. template:
    34. metadata:
    35. labels:
    36. app: nexus
    37. spec:
    38. containers:
    39. - name: nexus
    40. image: sonatype/nexus3:3.28.0
    41. imagePullPolicy: IfNotPresent
    42. ports:
    43. - containerPort: 8081
    44. name: web
    45. protocol: TCP
    46. livenessProbe:
    47. httpGet:
    48. path: /
    49. port: 8081
    50. initialDelaySeconds: 70
    51. periodSeconds: 30
    52. failureThreshold: 6
    53. readinessProbe:
    54. httpGet:
    55. path: /
    56. port: 8081
    57. initialDelaySeconds: 60
    58. periodSeconds: 30
    59. failureThreshold: 6
    60. resources:
    61. limits:
    62. cpu: 1000m
    63. memory: 2Gi
    64. requests:
    65. cpu: 500m
    66. memory: 512Mi
    67. volumeMounts:
    68. - name: nexus-data
    69. mountPath: /nexus-data
    70. volumes:
    71. - name: nexus-data
    72. persistentVolumeClaim:
    73. claimName: nexus-pvc
    74. ---
    75. apiVersion: v1
    76. kind: Service
    77. metadata:
    78. name: nexus
    79. namespace: nexus
    80. labels:
    81. app: nexus
    82. spec:
    83. selector:
    84. app: nexus
    85. type: NodePort
    86. ports:
    87. - name: web
    88. protocol: TCP
    89. port: 8081
    90. targetPort: 8081
    91. nodePort: 30001

    (11)生成资源

    [root@master nexus]# kubectl apply -f nexus.yaml 
    

    (12)查看pv,pvc

    [root@master ~]# kubectl get pv
    

    [root@master ~]# kubectl get pvc -n nexus
    

    (13) 查看pod,svc

    [root@master ~]# kubectl get pod,svc -n nexus
    

    (14) Kuboard查看

    工作负载

    容器组

    服务

    存储

    (15)部署ingress

    vim ingress-nexus.yaml

    1. apiVersion: networking.k8s.io/v1
    2. kind: Ingress
    3. metadata:
    4. name: ingress-nexus
    5. namespace: nexus
    6. spec:
    7. ingressClassName: "nginx"
    8. rules:
    9. - host: nexus.site
    10. http:
    11. paths:
    12. - path: /
    13. pathType: Prefix
    14. backend:
    15. service:
    16. name: nexus
    17. port:
    18. number: 8081

    (16)生成资源

    [root@master ~]# kubectl apply -f ingress-nexus.yaml 
    

    (17)查看ingress

    [root@master ~]# kubectl get ingress -n nexus
    

    (18)详细查看

    1. [root@master ~]# kubectl describe ingress ingress-nexus -n nexus
    2. Name: ingress-nexus
    3. Labels:
    4. Namespace: nexus
    5. Address: 10.101.23.182
    6. Ingress Class: nginx
    7. Default backend:
    8. Rules:
    9. Host Path Backends
    10. ---- ---- --------
    11. nexus.site
    12. / nexus:8081 (10.244.166.164:8081)
    13. Annotations:
    14. Events:
    15. Type Reason Age From Message
    16. ---- ------ ---- ---- -------
    17. Normal Sync 68s (x2 over 82s) nginx-ingress-controller Scheduled for sync
    18. Normal Sync 68s (x2 over 82s) nginx-ingress-controller Scheduled for sync

    (19)Kuboard查看

    应用路由

    详细信息

    (20)master节点修改hosts

    [root@master ~]# vim /etc/hosts
    

    (21)curl测试

    (22)物理机修改hosts

    (23)访问系统

    http://nexus.site:31820

    (24)K8S进入容器获取nexus初始的登录密码

    1. [root@master ~]# kubectl exec -it nexus-8498fc57cc-c82qr -n nexus /bin/bash
    2. ……
    3. cat /nexus-data/admin.password

    (25)输入用户名和密码

    1. 账号:admin
    2. 密码:上面获取的初始密码

    (26)进入系统

    初始化操作,下一步

    修改密码

     先设置允许匿名访问

    完成

    (26)登录成功

    (27)查看挂载情况(内容一致)

    NFS

    1. [root@master ~]# cd /opt/nexus/
    2. [root@master nexus]# ls
    3. blobs db etc instances karaf.pid lock nexus.yaml port tmp
    4. cache elasticsearch generated-bundles javaprefs keystores log orient restore-from-backup

    K8S容器

    1. [root@master ~]# kubectl exec -it nexus-8498fc57cc-c82qr -n nexus /bin/bash
    2. kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.
    3. bash-4.4$ ls
    4. bin dev help.1 lib licenses media nexus-data proc run srv tmp uid_template.sh var
    5. boot etc home lib64 lost+found mnt opt root sbin sys uid_entrypoint.sh usr
    6. bash-4.4$ cd nexus-data/
    7. bash-4.4$ ls
    8. blobs db etc instances karaf.pid lock nexus.yaml port tmp
    9. cache elasticsearch generated-bundles javaprefs keystores log orient restore-from-backup
    10. bash-4.4$ exit
    11. exit

    (28)其他方式的nexus部署

    可以参考本人博客:

    持续集成交付CICD:CentOS 7 安装 Nexus 3.63-CSDN博客

    二、问题

    1.volumeMode有哪几种模式

    (1)分类

    1. 针对 PV 持久卷,Kubernetes 支持两种卷模式(volumeModes):Filesystem(文件系统) 和 Block(块)。
    2. volumeMode 是一个可选的 API 参数。 如果该参数被省略,默认的卷模式是 Filesystem。
    3. volumeMode 属性设置为 Filesystem 的卷会被 Pod 挂载(Mount) 到某个目录。 如果卷的存储来自某块设备而该设备目前为空,Kuberneretes 会在第一次挂载卷之前 在设备上创建文件系统。

  • 相关阅读:
    【GYM 102832H】【模板】Combination Lock(二分图博弈)
    Elasticsearch的索引,类型,映射,文档相关名词简介
    springcloud11:Hystrix服务降级(断路器)
    cx3588 Recovery HDMI 没显示
    【软件安装&环境配置】vscode 安装界面没有出现安装路径的选择 的解决,以及vscode的删除的问题
    随心笔记,第四更
    python基于django的学生在线考试自动阅卷系统(含错题本功能)
    什么是泛型编程和模板技术?C语言中如何实现泛型编程?
    【Educoder数据挖掘实训】了解数据
    springboot实现用户统一认证、管理(单点登录)
  • 原文地址:https://blog.csdn.net/cronaldo91/article/details/138196213