Kubernetes adalah sumber terbuka yang dikembangkan oleh Google untuk mengelola aplikasi yang dikontainerisasi. Untuk mendeploy Odoo di Kubernetes, kita harus mengonfigurasi kubectl di Cluster kita.
Sebelum memulai anda perlu memiliki sebuah klaster Kubernetes, dan command line tool kubectl harus dikonfigurasi untuk berkomunikasi dengan klaster Anda.
PersistentVolumeClaims dan PersistentVolumes
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: odoo-web-17-claim
labels:
app: web
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 35Gi
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: odoo-conf-17-claim
labels:
app: web
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: odoo-addons-17-claim
labels:
app: web
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 15Gi
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: odoo-db-17-claim
labels:
app: db
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 30Gi
Deployment Odoo dan Postgresql
kind: Deployment
apiVersion: apps/v1
metadata:
name: web
labels:
io.kompose.service: web
annotations:
kompose.cmd: kompose -f odoo.yaml convert
kompose.version: 1.26.0 (40646f47)
spec:
replicas: 1
selector:
matchLabels:
io.kompose.service: web
template:
metadata:
creationTimestamp: null
labels:
io.kompose.service: web
annotations:
kompose.cmd: kompose -f odoo.yaml convert
kompose.version: 1.26.0 (40646f47)
spec:
volumes:
- name: odoo-web-data-17
persistentVolumeClaim:
claimName: odoo-web-17-claim
- name: odoo-conf-17
persistentVolumeClaim:
claimName: odoo-conf-17-claim
- name: odoo-addons-17
persistentVolumeClaim:
claimName: odoo-addons-17-claim
- name: time-zone
hostPath:
path: /usr/share/zoneinfo/Asia/Jakarta
type: ''
containers:
- name: web
image: odoo:latest
ports:
- name: http
containerPort: 8069
protocol: TCP
- name: other
containerPort: 8071
protocol: TCP
- name: websocket
containerPort: 8072
protocol: TCP
env:
- name: HOST
value: db
- name: PASSWORD
value: '123456'
- name: USER
value: odoo
resources: {}
volumeMounts:
- name: odoo-web-data-17
mountPath: /var/lib/odoo
- name: odoo-conf-17
mountPath: /etc/odoo
- name: odoo-addons-17
mountPath: /mnt/extra-addons
- name: time-zone
mountPath: /etc/localtime
restartPolicy: Always
kind: Deployment
apiVersion: apps/v1
metadata:
name: db
labels:
io.kompose.service: db
spec:
replicas: 1
selector:
matchLabels:
io.kompose.service: db
template:
metadata:
creationTimestamp: null
labels:
io.kompose.service: db
annotations:
kompose.cmd: kompose -f odoo.yaml convert
kompose.version: 1.26.0 (40646f47)
spec:
volumes:
- name: odoo-db-data-17
persistentVolumeClaim:
claimName: odoo-db-17-claim
- name: time-zone-db
hostPath:
path: /usr/share/zoneinfo/Asia/Jakarta
type: ''
containers:
- name: db
image: postgres:latest
env:
- name: PGDATA
value: /var/lib/postgresql/data/pgdata
- name: POSTGRES_DB
value: postgres
- name: POSTGRES_PASSWORD
value: '123456'
- name: POSTGRES_USER
value: odoo
resources: {}
volumeMounts:
- name: odoo-db-data-17
mountPath: /var/lib/postgresql/data/pgdata
- name: time-zone-db
mountPath: /etc/localtime
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
imagePullPolicy: Always
Service Odoo dan Postgresql
kind: Service
apiVersion: v1
metadata:
name: web
labels:
io.kompose.service: web
annotations:
kompose.cmd: kompose -f odoo.yaml convert
kompose.version: 1.26.0 (40646f47)
spec:
ports:
- name: http
protocol: TCP
port: 8069
targetPort: 8069
- name: websocket
protocol: TCP
port: 8072
targetPort: 8072
selector:
io.kompose.service: web
kind: Service
apiVersion: v1
metadata:
name: db
labels:
io.kompose.service: db
annotations:
kompose.cmd: kompose -f odoo.yaml convert
kompose.version: 1.26.0 (40646f47)
spec:
ports:
- name: postgres
protocol: TCP
port: 5432
targetPort: 5432
selector:
io.kompose.service: db
Sampai disini odoo sudah bisa diakses menggunakan IP cluster http://ClusterIP:8069 supaya bisa diakses dari luar cluster perlu menambah nginx ingress.
Odoo Ingress
Aktifkan proxy mode pada odoo configuration
/etc/nginx/sites-enabled/odoo.conf
proxy_mode = True
kind: Ingress
apiVersion: networking.k8s.io/v1
metadata:
name: odoo-ingress
annotations:
cert-manager.io/cluster-issuer: letsencrypt
nginx.ingress.kubernetes.io/client-max-body-size: 8m
nginx.ingress.kubernetes.io/connection-proxy-header: keep-alive
nginx.ingress.kubernetes.io/proxy-body-size: 16m
nginx.ingress.kubernetes.io/proxy-buffer-size: 8k
nginx.ingress.kubernetes.io/proxy-connect-timeout: '3600'
nginx.ingress.kubernetes.io/proxy-max-temp-file-size: 1024m
nginx.ingress.kubernetes.io/proxy-read-timeout: '3600'
nginx.ingress.kubernetes.io/proxy-send-timeout: '3600'
spec:
ingressClassName: public
tls:
- hosts:
- example.com
secretName: example-tls
rules:
- host: example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: web
port:
number: 8069
Odoo sudah bisa diakses menggunakan domain https://example.com
Deployment Odoo 17 Kubernetes