1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
| var_base=/root/deploy
var_app=$var_base/nexus3
var_version=3.55.0
mkdir -p $var_app
cd $var_app
docker pull sonatype/nexus3:$var_version
docker tag sonatype/nexus3:$var_version harbor.example.com/library/nexus3:$var_version
docker push harbor.example.com/library/nexus3:$var_version
APP_NAME="nexus3"
STORAGE_CLASS="rook-cephfs"
PVC_VOLUME_MODE="Filesystem"
PVC_RESOURCES_REQUESTS="100Gi"
PVC_ACCESS_MODES="ReadWriteMany"
NAMESPACE="middleware"
REPLICAS=1
IMAGE="harbor.example.com/library/nexus3:$var_version"
RESOURCES_REQUESTS_CPU="500m"
RESOURCES_LIMITS_CPU="4000m"
RESOURCES_REQUESTS_MEMORY="512Mi"
RESOURCES_LIMITS_MEMORY="3Gi"
CONTAINER_PORT=8081
PORT_NAME="http-port"
PORT_PROTOCOL="TCP"
SERVICE_PORT=8081
DATA_VOLUMES_NAME='data'
DATA_VOLUMES_MOUNTPATH='/nexus-data'
SERVICE_PORT_NAME="http"
INGRESS_CLASS_NAME="nginx"
INGRESS_HOST_NAME="nexus3.example.com"
cat <<EOF | tee $var_app/pvc.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: ${APP_NAME}-pvc
namespace: ${NAMESPACE}
spec:
storageClassName: ${STORAGE_CLASS}
volumeMode: ${PVC_VOLUME_MODE}
resources:
requests:
storage: ${PVC_RESOURCES_REQUESTS}
accessModes:
- ${PVC_ACCESS_MODES}
EOF
kubectl apply -f $var_app/pvc.yaml
cat <<EOF | tee $var_app/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: ${NAMESPACE}
name: ${APP_NAME}
spec:
strategy:
type: Recreate
selector:
matchLabels:
app: ${APP_NAME}
replicas: ${REPLICAS}
template:
metadata:
labels:
app: ${APP_NAME}
spec:
volumes:
- name: ${DATA_VOLUMES_NAME}
persistentVolumeClaim:
claimName: ${APP_NAME}-pvc
initContainers:
- name: volume-mount-hack
image: harbor.example.com/library/busybox:1.36.1
command: ["/bin/sh", "-c", "chown -R 200 /opt"]
volumeMounts:
- name: ${DATA_VOLUMES_NAME}
mountPath: /opt
containers:
- name: ${APP_NAME}
image: ${IMAGE}
ports:
- containerPort: ${CONTAINER_PORT}
name: ${PORT_NAME}
protocol: ${PORT_PROTOCOL}
resources:
requests:
cpu: ${RESOURCES_REQUESTS_CPU}
memory: ${RESOURCES_REQUESTS_MEMORY}
limits:
cpu: ${RESOURCES_LIMITS_CPU}
memory: ${RESOURCES_LIMITS_MEMORY}
volumeMounts:
- name: ${DATA_VOLUMES_NAME}
mountPath: ${DATA_VOLUMES_MOUNTPATH}
readinessProbe:
tcpSocket:
port: ${PORT_NAME}
initialDelaySeconds: 5
periodSeconds: 10
livenessProbe:
tcpSocket:
port: ${PORT_NAME}
initialDelaySeconds: 15
periodSeconds: 20
startupProbe:
tcpSocket:
port: ${PORT_NAME}
failureThreshold: 30
periodSeconds: 10
EOF
kubectl apply -f $var_app/deployment.yaml
cat <<EOF | tee $var_app/service.yaml
apiVersion: v1
kind: Service
metadata:
name: ${APP_NAME}-svc
namespace: ${NAMESPACE}
labels:
app: ${APP_NAME}
spec:
ports:
- name: ${SERVICE_PORT_NAME}
port: ${SERVICE_PORT}
protocol: ${PORT_PROTOCOL}
targetPort: ${CONTAINER_PORT}
selector:
app: ${APP_NAME}
EOF
kubectl apply -f $var_app/service.yaml
cat <<EOF | tee $var_app/ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ${APP_NAME}-ingress
namespace: ${NAMESPACE}
annotations:
cert-manager.io/cluster-issuer: letsencrypt-prod
ingress.kubernetes.io/proxy-body-size: 1024m
ingress.kubernetes.io/ssl-redirect: "true"
kubernetes.io/tls-acme: "true"
nginx.ingress.kubernetes.io/proxy-body-size: 1024m
nginx.ingress.kubernetes.io/ssl-redirect: "true"
nginx.org/client-max-body-size: 1024m
spec:
ingressClassName: ${INGRESS_CLASS_NAME}
rules:
- host: ${INGRESS_HOST_NAME}
http:
paths:
- pathType: Prefix
path: "/"
backend:
service:
name: ${APP_NAME}-svc
port:
number: ${SERVICE_PORT}
tls:
- hosts:
- ${INGRESS_HOST_NAME}
secretName: nexus3-example-com-tls
EOF
kubectl apply -f $var_app/ingress.yaml
kubectl -n middleware exec nexus3-64694bd8c9-5bblf -c nexus3 -- cat /nexus-data/admin.password
f8bda0e2-e68d-42aa-978f-197fbc85b320
修改密码为:
Password
|