diff --git a/README.md b/README.md index c635b5b..2474acf 100644 --- a/README.md +++ b/README.md @@ -17,4 +17,25 @@ kubectl apply -f ingress-service.yaml This will create the necessary resources in the cluster, including a deployment for the Ghost app, a service for connecting to the MySQL server, and an ingress service for routing traffic to the Ghost app via the nginx-proxy with https and http. Volumes -This configuration is using a Persistent Volume to store the Ghost blog data, this can be done by creating a persistent volume and persistent volume claim, and then referencing it in the ghost-blog-deployment.yaml file. \ No newline at end of file +This configuration is using a Persistent Volume to store the Ghost blog data, this can be done by creating a persistent volume and persistent volume claim, and then referencing it in the ghost-blog-deployment.yaml file. + +# ingress-service.yaml +In this example, $(VAR_HOST) and $(SECRET_NAME) are variables that are stored in a configMap and a Secret, respectively. These variables can be managed and updated separately from the YAML files, making it easier to update and maintain your configuration. + +To use variables in your YAML files, you'll first need to create a configMap and a Secret that contains the variables you need. You can do this using the kubectl command-line tool. + +For configMap, you can create it with the following command: + +Copy code +kubectl create configmap my-config-map --from-literal=VAR_HOST=example.com +And for Secret: + +Copy code +kubectl create secret generic my-secret --from-literal=SECRET_NAME=mysecret +Once you've created the configMap and Secret, you can reference them in your YAML files using the $(VAR_NAME) syntax. + +You can also manage and update the variables in the configMap and Secret using kubectl commands. + +It's important to note that configMap and Secret are not the only way to use variables in Kubernetes, you can also use other tools like Helm or Kustomize. + +# \ No newline at end of file diff --git a/deployments/ghost-blog-deployment.yaml b/deployments/ghost-blog-deployment.yaml index c319c92..e4b3796 100644 --- a/deployments/ghost-blog-deployment.yaml +++ b/deployments/ghost-blog-deployment.yaml @@ -2,8 +2,9 @@ apiVersion: apps/v1 kind: Deployment metadata: name: ghost-blog + namespace: blog spec: - replicas: 1 + replicas: 2 selector: matchLabels: app: ghost-blog @@ -17,45 +18,28 @@ spec: image: ghost:latest ports: - containerPort: 2368 - resources: - limits: - memory: "512Mi" - cpu: "500m" - requests: - memory: "256Mi" - cpu: "250m" env: - name: database__client value: mysql - name: database__connection__host - value: mysql + value: mysql-service - name: database__connection__user - value: ghost + value: $(MYSQL_USER) - name: database__connection__password - value: ghostpassword - - name: database__connection__database - value: ghost - - name: nginx-proxy - image: nginx:latest - ports: - - containerPort: 80 - - containerPort: 443 + value: $(MYSQL_PASSWORD) + - name: url resources: limits: - memory: "512Mi" - cpu: "500m" + cpu: "0.5" + memory: "1Gi" requests: - memory: "256Mi" - cpu: "250m" - env: - - name: ghost-blog-nginx-proxy - value: ghost-blog - - name: ghost-blog-nginx-config - value: /etc/nginx/conf.d/default.conf + cpu: "0.1" + memory: "512Mi" volumeMounts: - - name: ghost-blog-nginx-config-volume - mountPath: /etc/nginx/conf.d/ + - name: ghost-persistent-storage + mountPath: /var/lib/ghost/content volumes: - - name: ghost-blog-nginx-config-volume - configMap: - name: ghost-blog-nginx-config + - name: ghost-persistent-storage + persistentVolumeClaim: + claimName: ghost-pvc + diff --git a/deployments/mysql-deployment.yaml b/deployments/mysql-deployment.yaml index d14a4fb..a4b149f 100644 --- a/deployments/mysql-deployment.yaml +++ b/deployments/mysql-deployment.yaml @@ -2,6 +2,9 @@ apiVersion: apps/v1 kind: Deployment metadata: name: mysql + namespace: blog + labels: + app: mysql spec: replicas: 1 selector: @@ -17,19 +20,26 @@ spec: image: mysql:latest ports: - containerPort: 3306 - resources: - limits: - memory: "512Mi" - cpu: "500m" - requests: - memory: "256Mi" - cpu: "250m" env: - name: MYSQL_ROOT_PASSWORD value: password - name: MYSQL_DATABASE - value: ghost + value: ghost_db - name: MYSQL_USER value: ghost - name: MYSQL_PASSWORD - value: ghostpassword + value: password + resources: + limits: + cpu: "0.5" + memory: "1Gi" + requests: + cpu: "0.1" + memory: "512Mi" + volumeMounts: + - name: mysql-persistent-storage + mountPath: /var/lib/mysql + volumes: + - name: mysql-persistent-storage + persistentVolumeClaim: + claimName: mysql-pvc diff --git a/namespace.yaml b/namespace.yaml new file mode 100644 index 0000000..a98aecf --- /dev/null +++ b/namespace.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: blog \ No newline at end of file diff --git a/networking/ingress-service.yaml b/networking/ingress-service.yaml index f732051..1d0eca4 100644 --- a/networking/ingress-service.yaml +++ b/networking/ingress-service.yaml @@ -1,37 +1,31 @@ apiVersion: networking.k8s.io/v1 kind: Ingress metadata: - name: ghost-blog-ingress + name: ingress-service + namespace: blog annotations: nginx.ingress.kubernetes.io/rewrite-target: / - kubernetes.io/ingress.class: nginx - cert-manager.io/cluster-issuer: letsencrypt-prod + nginx.ingress.kubernetes.io/configuration-snippet: | + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header Host $host; + proxy_pass_request_headers on; spec: - tls: - - hosts: - - example.com - secretName: example-com-tls rules: - - host: example.com - http: - paths: - - path: / - pathType: Prefix - pathRewrite: / - backend: - service: - name: ghost-blog-service - port: - name: http - - host: example.com - http: - paths: - - path: / - pathType: Prefix - pathRewrite: / - backend: - service: - name: ghost-blog-service - port: - name: https - + - host: $(VAR_HOST) + http: + paths: + - path: / + pathType: Prefix + pathRewrite: /ghost/ + backend: + service: + name: ghost-blog-service + port: + name: http + path: / + tls: + - hosts: + - $(VAR_HOST) + secretName: $(SECRET_NAME) diff --git a/services/ghost-blog-service.yaml b/services/ghost-blog-service.yaml index c080399..42acd68 100644 --- a/services/ghost-blog-service.yaml +++ b/services/ghost-blog-service.yaml @@ -2,6 +2,7 @@ apiVersion: v1 kind: Service metadata: name: ghost-blog-service + namespace: blog spec: selector: app: ghost-blog diff --git a/services/mysql-service.yaml b/services/mysql-service.yaml index 676ae37..e25c180 100644 --- a/services/mysql-service.yaml +++ b/services/mysql-service.yaml @@ -2,6 +2,7 @@ apiVersion: v1 kind: Service metadata: name: mysql-service + namespace: blog spec: selector: app: mysql