diff --git a/mysql/kustomize/base/kustomization.yaml b/mysql/kustomize/base/kustomization.yaml index ab03512..3878caf 100644 --- a/mysql/kustomize/base/kustomization.yaml +++ b/mysql/kustomize/base/kustomization.yaml @@ -3,3 +3,5 @@ resources: - mysql_statefulset.yaml - mysql_service.yaml +- phpmyadmin_deployment.yaml +- phpmyadmin_service.yaml diff --git a/mysql/kustomize/base/mysql_service.yaml b/mysql/kustomize/base/mysql_service.yaml index 7c82043..563a0b0 100644 --- a/mysql/kustomize/base/mysql_service.yaml +++ b/mysql/kustomize/base/mysql_service.yaml @@ -4,6 +4,8 @@ metadata: name: db-service spec: type: ClusterIP + selector: + service: db ports: - protocol: TCP port: 3306 diff --git a/mysql/kustomize/base/mysql_statefulset.yaml b/mysql/kustomize/base/mysql_statefulset.yaml index e99f9c2..ab76a52 100644 --- a/mysql/kustomize/base/mysql_statefulset.yaml +++ b/mysql/kustomize/base/mysql_statefulset.yaml @@ -1,16 +1,23 @@ apiVersion: apps/v1 kind: StatefulSet metadata: - name: db-deployment + name: db-statefulset + labels: + service: db spec: serviceName: db-service replicas: 1 selector: + matchLabels: + service: db template: + metadata: + labels: + service: db spec: containers: - name: mysql - image: mysql:9 + image: mysql resources: requests: memory: "512Mi" diff --git a/mysql/kustomize/base/phpmyadmin_deployment.yaml b/mysql/kustomize/base/phpmyadmin_deployment.yaml new file mode 100644 index 0000000..7b0cb73 --- /dev/null +++ b/mysql/kustomize/base/phpmyadmin_deployment.yaml @@ -0,0 +1,38 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: phpmyadmin-deployment + labels: + service: phpmyadmin +spec: + replicas: 1 + selector: + matchLabels: + service: phpmyadmin + template: + metadata: + labels: + service: phpmyadmin + spec: + containers: + - name: phpmyadmin + image: phpmyadmin + resources: + limits: + memory: "256Mi" + cpu: "1000m" + ports: + - containerPort: 80 + env: + - name: PMA_HOST + valueFrom: + configMapKeyRef: + name: mysql-configmap + key: mysql-server + - name: PMA_USER + value: root + - name: PMA_PASSWORD + valueFrom: + secretKeyRef: + name: mysql-secret + key: mysql-root-password \ No newline at end of file diff --git a/mysql/kustomize/base/phpmyadmin_service.yaml b/mysql/kustomize/base/phpmyadmin_service.yaml new file mode 100644 index 0000000..a8a4849 --- /dev/null +++ b/mysql/kustomize/base/phpmyadmin_service.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Service +metadata: + name: phpmyadmin-service +spec: + type: ClusterIP + selector: + service: phpmyadmin + ports: + - protocol: TCP + port: 80 + targetPort: 80 \ No newline at end of file diff --git a/mysql/kustomize/overlays/default/kustomization.yaml b/mysql/kustomize/overlays/default/kustomization.yaml new file mode 100644 index 0000000..e88fb22 --- /dev/null +++ b/mysql/kustomize/overlays/default/kustomization.yaml @@ -0,0 +1,34 @@ +resources: +- ../../base +- phpmyadmin_ingress.yaml + +namespace: default + +labels: +- includeSelectors: true + pairs: + app: mysql + +commonAnnotations: + owner: florian + +namePrefix: mysql- + +images: +- name: mysql + newName: mysql + newTag: "9" +- name: phpmyadmin + newName: phpmyadmin + newTag: "5.2" + +patches: +- path: replica.yaml + +configMapGenerator: +- name: mysql-configmap + env: mysql-configmap.properties + +secretGenerator: +- name: mysql-secret + env: mysql-secret.properties \ No newline at end of file diff --git a/mysql/kustomize/overlays/default/mysql-configmap.properties b/mysql/kustomize/overlays/default/mysql-configmap.properties new file mode 100644 index 0000000..40aec8a --- /dev/null +++ b/mysql/kustomize/overlays/default/mysql-configmap.properties @@ -0,0 +1 @@ +mysql-server=mysql-db-service \ No newline at end of file diff --git a/mysql/kustomize/overlays/default/mysql-secret.properties b/mysql/kustomize/overlays/default/mysql-secret.properties new file mode 100644 index 0000000..0b849e1 --- /dev/null +++ b/mysql/kustomize/overlays/default/mysql-secret.properties @@ -0,0 +1,3 @@ +# Encoded base64 string required by kubernetes +# echo -n '' | base64 +mysql-root-password="cm9vdA==" \ No newline at end of file diff --git a/mysql/kustomize/overlays/default/phpmyadmin_ingress.yaml b/mysql/kustomize/overlays/default/phpmyadmin_ingress.yaml new file mode 100644 index 0000000..7644870 --- /dev/null +++ b/mysql/kustomize/overlays/default/phpmyadmin_ingress.yaml @@ -0,0 +1,18 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: phpmyadmin-ingress + annotations: + nginx.ingress.kubernetes.io/rewrite-target: / +spec: + ingressClassName: nginx + rules: + - http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: phpmyadmin-service + port: + number: 80 \ No newline at end of file diff --git a/mysql/kustomize/overlays/default/replica.yaml b/mysql/kustomize/overlays/default/replica.yaml new file mode 100644 index 0000000..c72185b --- /dev/null +++ b/mysql/kustomize/overlays/default/replica.yaml @@ -0,0 +1,6 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: phpmyadmin-deployment +spec: + replicas: 2 \ No newline at end of file