diff --git a/README.md b/README.md index c587e6e..c368812 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ Role Name ========= -Ansible role to deploy eom services. +Ansible role to deploy EOM services on Kubernetes. Requirements ------------ diff --git a/files/httpd-proxy.conf b/files/httpd-proxy.conf index 34d6fc6..79d12c0 100644 --- a/files/httpd-proxy.conf +++ b/files/httpd-proxy.conf @@ -2,6 +2,40 @@ LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_http_module modules/mod_proxy_http.so LoadModule rewrite_module modules/mod_rewrite.so + + ServerName api.eom.dev + ServerAlias *.api.eom.dev + + ProxyRequests Off + ProxyPreserveHost On + + + Order deny,allow + Allow from all + + + ProxyPass / http://api/ + ProxyPassReverse / http://api/ + + + ServerName api.eom.dev + ServerAlias *.api.eom.dev + + SSLProxyEngine On + SSLCertificateFile "/usr/local/apache2/conf/server.crt" + SSLCertificateKeyFile "/usr/local/apache2/conf/server.key" + ProxyRequests Off + ProxyPreserveHost On + + + Order deny,allow + Allow from all + + + ProxyPass / http://api/ + ProxyPassReverse / http://api/ + + ServerName git.eom.dev ServerAlias *.git.eom.dev diff --git a/files/httpd-wsgi.conf b/files/httpd-wsgi.conf new file mode 100644 index 0000000..87b370e --- /dev/null +++ b/files/httpd-wsgi.conf @@ -0,0 +1,3 @@ +LoadModule wsgi_module modules/mod_wsgi.so + +WSGIScriptAlias / /usr/local/apache2/htdocs/wsgi_app.py diff --git a/tasks/api.yaml b/tasks/api.yaml new file mode 100644 index 0000000..1fc5839 --- /dev/null +++ b/tasks/api.yaml @@ -0,0 +1,67 @@ +--- +# tasks file for api +- name: Create a config map for api + vars: + httpd_server_name: "api.eom.dev" + httpd_conf_extra: + - httpd-auth.conf + - httpd-wsgi.conf + k8s: + state: present + api_version: v1 + kind: ConfigMap + name: api + namespace: "eom-{{ target_namespace }}" + definition: + data: + httpd.conf: "{{ lookup('template', 'httpd.conf.j2') }}" + httpd-auth.conf: "{{ lookup('template', 'httpd-auth.conf.j2') }}" + httpd-wsgi.conf: "{{ lookup('file', 'httpd-wsgi.conf') }}" + mime.types: "{{ lookup('file', 'mime.types') }}" + +- name: Create a deployment + k8s: + definition: + apiVersion: v1 + kind: Deployment + metadata: + name: api + namespace: "eom-{{ target_namespace }}" + spec: + replicas: 1 + selector: + matchLabels: + app: api + template: + metadata: + labels: + app: api + spec: + containers: + - name: api + image: ericomeehan/api + volumeMounts: + - name: config + mountPath: /usr/local/apache2/conf + ports: + - containerPort: 80 + volumes: + - name: config + configMap: + name: api + +- name: Expose deployment as a service + k8s: + definition: + apiVersion: v1 + kind: Service + metadata: + name: api + namespace: "eom-{{ target_namespace }}" + spec: + selector: + app: api + ports: + - port: 80 + name: api-80 + type: ClusterIP diff --git a/tasks/influxdb.yaml b/tasks/influxdb.yaml new file mode 100644 index 0000000..fd180e1 --- /dev/null +++ b/tasks/influxdb.yaml @@ -0,0 +1,95 @@ +--- +# tasks file for influxdb +- name: Create persistent volume for influxdb + k8s: + state: present + definition: + apiVersion: v1 + kind: PersistentVolume + metadata: + name: "eom-{{ target_namespace }}-influxdb" + spec: + capacity: + storage: 32Gi + accessModes: + - ReadWriteMany + persistentVolumeReclaimPolicy: Retain + storageClassName: standard + hostPath: + path: "/data/store-0/eom-{{ target_namespace }}/influxdb" + nodeAffinity: + required: + nodeSelectorTerms: + - matchExpressions: + - key: kubernetes.io/hostname + operator: In + values: + - alpha-worker-0 + +- name: Create a persistent volume claim for influxdb + k8s: + state: present + definition: + apiVersion: v1 + kind: PersistentVolumeClaim + metadata: + name: influxdb + namespace: "eom-{{ target_namespace }}" + spec: + accessModes: + - ReadWriteMany + resources: + requests: + storage: 32Gi + storageClassName: standard + volumeName: "eom-{{ target_namespace }}-influxdb" + +- name: Create a deployment + k8s: + definition: + apiVersion: v1 + kind: Deployment + metadata: + name: influxdb + namespace: "eom-{{ target_namespace }}" + spec: + replicas: 1 + selector: + matchLabels: + app: influxdb + template: + metadata: + labels: + app: influxdb + spec: + containers: + - name: influxdb + image: bitnami/influxdb + volumeMounts: + - name: data + mountPath: /var/lib/mysql + ports: + - containerPort: 3306 + env: + key: INFLUXDB_ADMIN_USER_PASSWORD + value: "{{ influxdb_root_password }}" + volumes: + - name: data + persistentVolumeClaim: + claimName: influxdb + +- name: Expose deployment as a service + k8s: + definition: + apiVersion: v1 + kind: Service + metadata: + name: influxdb + namespace: "eom-{{ target_namespace }}" + spec: + selector: + app: influxdb + ports: + - port: 3306 + name: influxdb-3306 + type: ClusterIP diff --git a/tasks/main.yml b/tasks/main.yaml similarity index 100% rename from tasks/main.yml rename to tasks/main.yaml diff --git a/tasks/mariadb.yaml b/tasks/mariadb.yaml new file mode 100644 index 0000000..4823c7c --- /dev/null +++ b/tasks/mariadb.yaml @@ -0,0 +1,95 @@ +--- +# tasks file for mariadb +- name: Create persistent volume for mariadb + k8s: + state: present + definition: + apiVersion: v1 + kind: PersistentVolume + metadata: + name: "eom-{{ target_namespace }}-mariadb" + spec: + capacity: + storage: 32Gi + accessModes: + - ReadWriteMany + persistentVolumeReclaimPolicy: Retain + storageClassName: standard + hostPath: + path: "/data/store-0/eom-{{ target_namespace }}/mariadb" + nodeAffinity: + required: + nodeSelectorTerms: + - matchExpressions: + - key: kubernetes.io/hostname + operator: In + values: + - alpha-worker-0 + +- name: Create a persistent volume claim for mariadb + k8s: + state: present + definition: + apiVersion: v1 + kind: PersistentVolumeClaim + metadata: + name: mariadb + namespace: "eom-{{ target_namespace }}" + spec: + accessModes: + - ReadWriteMany + resources: + requests: + storage: 32Gi + storageClassName: standard + volumeName: "eom-{{ target_namespace }}-mariadb" + +- name: Create a deployment + k8s: + definition: + apiVersion: v1 + kind: Deployment + metadata: + name: mariadb + namespace: "eom-{{ target_namespace }}" + spec: + replicas: 1 + selector: + matchLabels: + app: mariadb + template: + metadata: + labels: + app: mariadb + spec: + containers: + - name: mariadb + image: mariadb + volumeMounts: + - name: data + mountPath: /var/lib/mysql + ports: + - containerPort: 3306 + env: + key: MARIADB_ROOT_PASSWORD + value: "{{ mariadb_root_password }}" + volumes: + - name: data + persistentVolumeClaim: + claimName: mariadb + +- name: Expose deployment as a service + k8s: + definition: + apiVersion: v1 + kind: Service + metadata: + name: mariadb + namespace: "eom-{{ target_namespace }}" + spec: + selector: + app: mariadb + ports: + - port: 3306 + name: mariadb-3306 + type: ClusterIP diff --git a/tasks/mongodb.yaml b/tasks/mongodb.yaml new file mode 100644 index 0000000..44cdcbd --- /dev/null +++ b/tasks/mongodb.yaml @@ -0,0 +1,96 @@ +--- +# tasks file for mongodb +- name: Create persistent volume for mongodb + k8s: + state: present + definition: + apiVersion: v1 + kind: PersistentVolume + metadata: + name: "eom-{{ target_namespace }}-mongodb" + spec: + capacity: + storage: 32Gi + accessModes: + - ReadWriteMany + persistentVolumeReclaimPolicy: Retain + storageClassName: standard + hostPath: + path: "/data/store-0/eom-{{ target_namespace }}/mongodb" + nodeAffinity: + required: + nodeSelectorTerms: + - matchExpressions: + - key: kubernetes.io/hostname + operator: In + values: + - alpha-worker-0 + +- name: Create a persistent volume claim for mongodb + k8s: + state: present + definition: + apiVersion: v1 + kind: PersistentVolumeClaim + metadata: + name: mongodb + namespace: "eom-{{ target_namespace }}" + spec: + accessModes: + - ReadWriteMany + resources: + requests: + storage: 32Gi + storageClassName: standard + volumeName: "eom-{{ target_namespace }}-mongodb" + +- name: Create a deployment + k8s: + definition: + apiVersion: v1 + kind: Deployment + metadata: + name: mongodb + namespace: "eom-{{ target_namespace }}" + spec: + replicas: 1 + selector: + matchLabels: + app: mongodb + template: + metadata: + labels: + app: mongodb + spec: + containers: + - name: mongodb + image: mongo + volumeMounts: + - name: data + mountPath: /var/lib/mysql + ports: + - containerPort: 3306 + env: + # TODO: check docs for extra vars + key: ME_CONFIG_MONGODB_ADMINPASSWORD + value: "{{ mongodb_root_password }}" + volumes: + - name: data + persistentVolumeClaim: + claimName: mongodb + +- name: Expose deployment as a service + k8s: + definition: + apiVersion: v1 + kind: Service + metadata: + name: mongodb + namespace: "eom-{{ target_namespace }}" + spec: + selector: + app: mongodb + ports: + - port: 8081 + name: mongodb-8081 + type: ClusterIP