Prérequis
MongoDB doit être préalablement installé et acecssible pour que YAPI fonctionne correctement.
Fichiers de configuration Kubernetes
Les manifests YAML suivants doivent être adaptés, notamment le namespace, selon votre environnement.
Déploiement (Deployment)
apiVersion: apps/v1
kind: Deployment
metadata:
name: yapi-application
namespace: dev-environment
labels:
app.kubernetes.io/name: yapi
app.kubernetes.io/component: backend
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: yapi
template:
metadata:
labels:
app.kubernetes.io/name: yapi
spec:
containers:
- name: yapi-server
image: harbor.internal.com/yapi/yapi:1.9.5
command: ["node", "server/app.js"]
ports:
- containerPort: 3000
name: http
protocol: TCP
volumeMounts:
- name: configuration-volume
mountPath: /yapi/config.json
subPath: config.json
resources:
requests:
cpu: 300m
memory: 256Mi
limits:
cpu: 600m
memory: 512Mi
volumes:
- name: configuration-volume
configMap:
name: yapi-settings
Service
apiVersion: v1
kind: Service
metadata:
name: yapi-service
namespace: dev-environment
labels:
app.kubernetes.io/name: yapi
spec:
type: ClusterIP
ports:
- port: 3000
targetPort: 3000
protocol: TCP
name: api
selector:
app.kubernetes.io/name: yapi
ConfigMap pour la configuration
apiVersion: v1
kind: ConfigMap
metadata:
name: yapi-settings
namespace: dev-environment
data:
config.json: |-
{
"closeRegister": true,
"port": "3000",
"adminAccount": "admin@example.org",
"db": {
"servername": "mongo-cluster",
"DATABASE": "yapidatabase",
"port": "27017",
"user": "yapiuser",
"pass": "yapipassword"
},
"mail": {
"enable": false,
"host": "smtp.mailprovider.com",
"port": 465,
"from": "noreply@example.org",
"auth": {
"user": "mailuser",
"pass": "mailpassword"
}
}
}
Ingress
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: yapi-ingress
namespace: dev-environment
spec:
rules:
- host: yapi.mydomain.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: yapi-service
port:
number: 3000