本地数据盘模式
把数据保存在node2和pod容器跑在node2
mkdir -p /var/nexus-data
chown -R 200 /var/nexus-data
apiVersion: v1
kind: PersistentVolume
metadata:
name: nexus-data
spec:
capacity:
storage: 5Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: local-storage
local:
path: /var/nexus-data
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- node2
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: nexus-data-pvc
spec:
accessModes:
- ReadWriteOnce
volumeMode: Filesystem
resources:
requests:
storage: 5Gi
storageClassName: local-storage
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nexus-deployment
spec:
replicas: 1
selector:
matchLabels:
app: nexus
template:
metadata:
labels:
app: nexus
spec:
nodeSelector:
kubernetes.io/hostname: "node2"
containers:
- name: nexus
image: sonatype/nexus3
ports:
- containerPort: 8081
- containerPort: 8082
- containerPort: 8083
volumeMounts:
- mountPath: /nexus-data
name: nexus-data
volumes:
- name: nexus-data
persistentVolumeClaim:
claimName: nexus-data-pvc
---
apiVersion: v1
kind: Service
metadata:
name: nexus-svc
spec:
selector:
app: nexus
type: NodePort
ports:
- name: web
protocol: TCP
port: 8081
targetPort: 8081
nodePort: 30081
- name: docker
protocol: TCP
port: 8082
targetPort: 8082
nodePort: 30082
- name: maven
protocol: TCP
port: 8083
targetPort: 8083
nodePort: 30083
[root@master ~]# kubectl get all |grep nexus*
pod/nexus-deployment-787578c7f6-w747l 1/1 Running 0 153m
service/nexus-svc NodePort 10.233.25.187 <none> 8081:30081/TCP,8082:30082/TCP,8083:30083/TCP 6h54m
deployment.apps/nexus-deployment 1/1 1 1 6h54m
replicaset.apps/nexus-deployment-787578c7f6 1 1 1 156m
[root@master ~]#
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: nexus
annotations:
kubernetes.io/ingress.class: "nginx"
spec:
rules:
- host: nexus.riyimei.cn
http:
paths:
- path: /
pathType: ImplementationSpecific
backend:
serviceName: nexus-svc
servicePort: 8081
- path: /
pathType: ImplementationSpecific
backend:
serviceName: nexus-svc
servicePort: 8082
- path: /
pathType: ImplementationSpecific
backend:
serviceName: nexus-svc
servicePort: 8083
Ingress 暴露服务
apiVersion: v1
kind: PersistentVolume
metadata:
name: nexus-data
spec:
capacity:
storage: 5Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: local-storage
local:
path: /var/nexus-data
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- node2
#storageClassName: nfs
#nfs:
#path: /var/nexus-data
#server: 192.168.0.250
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: nexus-data-pvc
spec:
accessModes:
- ReadWriteOnce
volumeMode: Filesystem
resources:
requests:
storage: 5Gi
storageClassName: local-storage
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nexus-deployment
spec:
replicas: 1
selector:
matchLabels:
app: nexus
template:
metadata:
labels:
app: nexus
spec:
nodeSelector:
kubernetes.io/hostname: "node2"
containers:
- name: nexus
image: sonatype/nexus3
ports:
- containerPort: 8081
- containerPort: 8082
- containerPort: 8083
volumeMounts:
- mountPath: /nexus-data
name: nexus-data
volumes:
- name: nexus-data
persistentVolumeClaim:
claimName: nexus-data-pvc
---
apiVersion: v1
kind: Service
metadata:
name: nexus-svc
spec:
selector:
app: nexus
type: ClusterIP
ports:
- name: web
protocol: TCP
port: 8081
- name: docker
protocol: TCP
port: 8082
- name: maven
protocol: TCP
port: 8083
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: nexus
annotations:
kubernetes.io/ingress.class: "nginx"
spec:
rules:
- host: nexus.riyimei.cn
http:
paths:
- path: /
pathType: ImplementationSpecific
backend:
serviceName: nexus-svc
servicePort: 8081
- path: /
pathType: ImplementationSpecific
backend:
serviceName: nexus-svc
servicePort: 8082
- path: /
pathType: ImplementationSpecific
backend:
serviceName: nexus-svc
servicePort: 8083
[root@master ~]# kubectl get all |grep nexus*
pod/nexus-deployment-787578c7f6-w747l 1/1 Running 0 172m
service/nexus-svc ClusterIP 10.233.25.187 <none> 8081/TCP,8082/TCP,8083/TCP 7h14m
deployment.apps/nexus-deployment 1/1 1 1 7h14m
replicaset.apps/nexus-deployment-787578c7f6 1 1 1 176m
[root@master ~]# kubectl get ingress |grep nexus*
Warning: extensions/v1beta1 Ingress is deprecated in v1.14+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress
nexus <none> nexus.riyimei.cn 192.168.11.151,192.168.11.152 80 15m
[root@master ~]# kubectl get pvc |grep nexus*
nexus-data-pvc Bound nexus-data 5Gi RWO local-storage 7h15m
[root@master ~]# kubectl get pv |grep nexus*
nexus-data 5Gi RWO Retain Bound default/nexus-data-pvc local-storage 7h15m
[root@master ~]#
nfs共享模式
apiVersion: v1
kind: PersistentVolume
metadata:
name: nexus-data
spec:
capacity:
storage: 5Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: nfs
nfs:
path: /var/nfs/nexus-data
server: 192.168.0.250
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: nexus-data-pvc
spec:
accessModes:
- ReadWriteOnce
volumeMode: Filesystem
resources:
requests:
storage: 5Gi
storageClassName: nfs
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nexus-deployment
spec:
replicas: 1
selector:
matchLabels:
app: nexus
template:
metadata:
labels:
app: nexus
spec:
containers:
- name: nexus
image: sonatype/nexus3
ports:
- containerPort: 8081
- containerPort: 8082
- containerPort: 8083
volumeMounts:
- mountPath: /nexus-data
name: nexus-data
volumes:
- name: nexus-data
persistentVolumeClaim:
claimName: nexus-data-pvc
---
apiVersion: v1
kind: Service
metadata:
name: nexus-svc
spec:
selector:
app: nexus
type: NodePort
ports:
- name: web
protocol: TCP
port: 8081
targetPort: 8081
nodePort: 30081
- name: docker
protocol: TCP
port: 8082
targetPort: 8082
nodePort: 30082
- name: maven
protocol: TCP
port: 8083
targetPort: 8083
nodePort: 30083
软件初始化密码
[root@node2 ~]#
[root@node2 ~]# cd /var/nexus-data/
[root@node2 nexus-data]# ls -l
total 28
-rw-r--r-- 1 200 200 36 Jul 31 16:23 admin.password
drwxr-xr-x 3 200 200 21 Jul 31 16:23 blobs
drwxr-xr-x 331 200 200 8192 Jul 31 16:22 cache
drwxr-xr-x 6 200 200 113 Jul 31 16:23 db
drwxr-xr-x 3 200 200 19 Jul 31 16:23 elasticsearch
drwxr-xr-x 3 200 200 45 Jul 31 16:03 etc
drwxr-xr-x 2 200 200 6 Jul 31 16:02 generated-bundles
drwxr-xr-x 2 200 200 33 Jul 31 16:02 instances
drwxr-xr-x 3 200 200 19 Jul 31 16:02 javaprefs
-rw-r--r-- 1 200 200 1 Jul 31 16:22 karaf.pid
drwxr-xr-x 3 200 200 18 Jul 31 16:03 keystores
-rw-r--r-- 1 200 200 35 Jul 31 16:22 lock
drwxr-xr-x 3 200 200 112 Jul 31 16:23 log
drwxr-xr-x 2 200 200 6 Jul 31 16:03 orient
-rw-r--r-- 1 200 200 5 Jul 31 16:22 port
drwxr-xr-x 2 200 200 6 Jul 31 16:03 restore-from-backup
drwxr-xr-x 8 200 200 281 Jul 31 16:23 tmp
[root@node2 nexus-data]# cat admin.password
3218527c-1c47-497c-867c-8b72188b01d0[root@node2 nexus-data]# pwd
/var/nexus-data
[root@node2 nexus-data]#