From c717c7e8f023a7d6df2ce53bd189137827a4a9ab Mon Sep 17 00:00:00 2001 From: Celestino Rey Date: Tue, 31 Jan 2023 08:53:52 +0100 Subject: [PATCH] Wordpress secrets en fichero. Helm de wordpress funcionando --- HelmCharts/helmWordpress.sh | 14 ++++ .../preparaWordpress/pv-local-mysql.yaml | 11 +++ .../preparaWordpress/pv-local-wordpress.yaml | 12 +++ HelmCharts/preparaWordpress/wp-namespace.yaml | 4 + HelmCharts/wordpress-chart/.helmignore | 23 ++++++ HelmCharts/wordpress-chart/Chart.yaml | 24 ++++++ .../templates/mysql-deployment.yaml | 70 ++++++++++++++++ .../templates/php-deployment.yaml | 56 +++++++++++++ .../templates/registry-secrets.yaml | 11 +++ .../templates/wordpress-deployment.yaml | 80 ++++++++++++++++++ .../templates/wordpress-secrets.yaml | 9 ++ HelmCharts/wordpress-chart/values.yaml | 82 +++++++++++++++++++ Wordpress/kustomization.yaml | 8 +- Wordpress/wordpress-secrets.yaml | 9 ++ 14 files changed, 406 insertions(+), 7 deletions(-) create mode 100644 HelmCharts/helmWordpress.sh create mode 100644 HelmCharts/preparaWordpress/pv-local-mysql.yaml create mode 100644 HelmCharts/preparaWordpress/pv-local-wordpress.yaml create mode 100644 HelmCharts/preparaWordpress/wp-namespace.yaml create mode 100644 HelmCharts/wordpress-chart/.helmignore create mode 100644 HelmCharts/wordpress-chart/Chart.yaml create mode 100755 HelmCharts/wordpress-chart/templates/mysql-deployment.yaml create mode 100644 HelmCharts/wordpress-chart/templates/php-deployment.yaml create mode 100644 HelmCharts/wordpress-chart/templates/registry-secrets.yaml create mode 100755 HelmCharts/wordpress-chart/templates/wordpress-deployment.yaml create mode 100644 HelmCharts/wordpress-chart/templates/wordpress-secrets.yaml create mode 100644 HelmCharts/wordpress-chart/values.yaml create mode 100644 Wordpress/wordpress-secrets.yaml diff --git a/HelmCharts/helmWordpress.sh b/HelmCharts/helmWordpress.sh new file mode 100644 index 00000000..96b83df5 --- /dev/null +++ b/HelmCharts/helmWordpress.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +if [ "$1" = "i" ] +then + kubectl apply -f ./preparaWordpress/wp-namespace.yaml + kubectl apply -f ./preparaWordpress/pv-local-mysql.yaml + kubectl apply -f ./preparaWordpress/pv-local-wordpress.yaml + helm install wordpress wordpress-chart/ +else + helm uninstall wordpress + kubectl delete -f ./preparaWordpress/wp-namespace.yaml + kubectl delete -f ./preparaWordpress/pv-local-mysql.yaml + kubectl delete -f ./preparaWordpress/pv-local-wordpress.yaml +fi diff --git a/HelmCharts/preparaWordpress/pv-local-mysql.yaml b/HelmCharts/preparaWordpress/pv-local-mysql.yaml new file mode 100644 index 00000000..b3fcc55e --- /dev/null +++ b/HelmCharts/preparaWordpress/pv-local-mysql.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: PersistentVolume +metadata: + name: wp-data +spec: + capacity: + storage: 20Gi + accessModes: + - ReadWriteOnce + hostPath: + path: "/mnt/cluster/wordpress/wordpress-db" diff --git a/HelmCharts/preparaWordpress/pv-local-wordpress.yaml b/HelmCharts/preparaWordpress/pv-local-wordpress.yaml new file mode 100644 index 00000000..d6d44b76 --- /dev/null +++ b/HelmCharts/preparaWordpress/pv-local-wordpress.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: PersistentVolume +metadata: + name: wp-folder +spec: + capacity: + storage: 10Gi + accessModes: + - ReadWriteOnce + hostPath: + path: "/mnt/cluster/wordpress/wordpress-wp" + diff --git a/HelmCharts/preparaWordpress/wp-namespace.yaml b/HelmCharts/preparaWordpress/wp-namespace.yaml new file mode 100644 index 00000000..d75fbe15 --- /dev/null +++ b/HelmCharts/preparaWordpress/wp-namespace.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: wordpress diff --git a/HelmCharts/wordpress-chart/.helmignore b/HelmCharts/wordpress-chart/.helmignore new file mode 100644 index 00000000..0e8a0eb3 --- /dev/null +++ b/HelmCharts/wordpress-chart/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/HelmCharts/wordpress-chart/Chart.yaml b/HelmCharts/wordpress-chart/Chart.yaml new file mode 100644 index 00000000..dcda9cb3 --- /dev/null +++ b/HelmCharts/wordpress-chart/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: wordpress-chart +description: A Helm chart for Kubernetes + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 0.1.0 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +# It is recommended to use it with quotes. +appVersion: "1.16.0" diff --git a/HelmCharts/wordpress-chart/templates/mysql-deployment.yaml b/HelmCharts/wordpress-chart/templates/mysql-deployment.yaml new file mode 100755 index 00000000..38ffba47 --- /dev/null +++ b/HelmCharts/wordpress-chart/templates/mysql-deployment.yaml @@ -0,0 +1,70 @@ +apiVersion: v1 +kind: Service +metadata: + name: wordpress-mysql + namespace: wordpress + labels: + app: wordpress +spec: + ports: + - port: 3306 + selector: + app: wordpress + tier: mysql + clusterIP: None +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: mysql-wp-pv-claim + namespace: wordpress + labels: + app: wordpress +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 20Gi +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: wordpress-mysql + namespace: wordpress + labels: + app: wordpress +spec: + selector: + matchLabels: + app: wordpress + tier: mysql + strategy: + type: Recreate + template: + metadata: + labels: + app: wordpress + tier: mysql + spec: + containers: + - image: docker-registry:32000/mariadb:1.0 + name: mysql + env: + - name: MYSQL_ROOT_PASSWORD + valueFrom: + secretKeyRef: + name: mysqlwp-pass + key: password + ports: + - containerPort: 3306 + name: mysql + volumeMounts: + - name: mysql-persistent-storage + mountPath: /var/lib/mysql + imagePullSecrets: + - name: reg-cred-secret + volumes: + - name: mysql-persistent-storage + persistentVolumeClaim: + claimName: mysql-wp-pv-claim diff --git a/HelmCharts/wordpress-chart/templates/php-deployment.yaml b/HelmCharts/wordpress-chart/templates/php-deployment.yaml new file mode 100644 index 00000000..a92b5042 --- /dev/null +++ b/HelmCharts/wordpress-chart/templates/php-deployment.yaml @@ -0,0 +1,56 @@ +apiVersion: v1 +kind: Service +metadata: + name: phpmyadmin-wordpress + namespace: wordpress + labels: + app: wordpress +spec: + selector: + app: wordpress + tier: phpmyadmin + type: NodePort + ports: + - name: phpadmin + port: 80 + nodePort: 30280 + targetPort: phpmyadm +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: phpmyadmin-wordpress + namespace: wordpress + labels: + app: wordpress +spec: + selector: + matchLabels: + app: wordpress + tier: phpmyadmin + strategy: + type: Recreate + template: + metadata: + labels: + app: wordpress + tier: phpmyadmin + spec: + containers: + - name: phpmyadmin + image: docker-registry:32000/phpmyadmin:1.0 + ports: + - containerPort: 80 + name: phpmyadm + env: + - name: PMA_HOST + value: wordpress-mysql + - name: PMA_PORT + value: "3306" + - name: MYSQL_ROOT_PASSWORD + valueFrom: + secretKeyRef: + name: mysqlwp-pass + key: password + imagePullSecrets: + - name: reg-cred-secret diff --git a/HelmCharts/wordpress-chart/templates/registry-secrets.yaml b/HelmCharts/wordpress-chart/templates/registry-secrets.yaml new file mode 100644 index 00000000..258edbb9 --- /dev/null +++ b/HelmCharts/wordpress-chart/templates/registry-secrets.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +data: + .dockerconfigjson: eyJhdXRocyI6eyJkb2NrZXItcmVnaXN0cnk6MzIwMDAiOnsidXNlcm5hbWUiOiJjcmV5bG9wZXoiLCJwYXNzd29yZCI6IlJleS0xMTc2IiwiYXV0aCI6IlkzSmxlV3h2Y0dWNk9sSmxlUzB4TVRjMiJ9fX0= +kind: Secret +metadata: + creationTimestamp: "2023-01-29T10:54:14Z" + name: reg-cred-secret + namespace: wordpress + resourceVersion: "19890385" + uid: 66b3b7c5-26c1-4e5a-af4e-dc973aaafe4b +type: kubernetes.io/dockerconfigjson diff --git a/HelmCharts/wordpress-chart/templates/wordpress-deployment.yaml b/HelmCharts/wordpress-chart/templates/wordpress-deployment.yaml new file mode 100755 index 00000000..266345cc --- /dev/null +++ b/HelmCharts/wordpress-chart/templates/wordpress-deployment.yaml @@ -0,0 +1,80 @@ +apiVersion: v1 +kind: Service +metadata: + name: wordpress + namespace: wordpress + labels: + app: wordpress +spec: + type: NodePort + ports: + - port: 80 + nodePort: 30088 + targetPort: wordpress + selector: + app: wordpress + tier: frontend +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: wp-pv-claim + namespace: wordpress + labels: + app: wordpress +spec: + accessModes: + - ReadWriteOnce + storageClassName: "" + resources: + requests: + storage: 10Gi +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: wordpress + namespace: wordpress + labels: + app: wordpress +spec: + selector: + matchLabels: + app: wordpress + tier: frontend + strategy: + type: Recreate + template: + metadata: + labels: + app: wordpress + tier: frontend + spec: + containers: + - image: docker-registry:32000/wordpress:1.0 + name: wordpress + env: + - name: WORDPRESS_DB_HOST + value: wordpress-mysql + - name: WORDPRESS_DB_PASSWORD + valueFrom: + secretKeyRef: + name: mysqlwp-pass + key: password + - name: WORDPRESS_DB_USER + valueFrom: + secretKeyRef: + name: mysqlwp-pass + key: db_user + ports: + - containerPort: 80 + name: wordpress + volumeMounts: + - name: wordpress-persistent-storage + mountPath: /var/www/html + imagePullSecrets: + - name: reg-cred-secret + volumes: + - name: wordpress-persistent-storage + persistentVolumeClaim: + claimName: wp-pv-claim diff --git a/HelmCharts/wordpress-chart/templates/wordpress-secrets.yaml b/HelmCharts/wordpress-chart/templates/wordpress-secrets.yaml new file mode 100644 index 00000000..613d49d7 --- /dev/null +++ b/HelmCharts/wordpress-chart/templates/wordpress-secrets.yaml @@ -0,0 +1,9 @@ +apiVersion: v1 +kind: Secret +metadata: + name: mysqlwp-pass + namespace: wordpress +data: + password: RHNhLTAyMTM= + db_user: cm9vdA== + db_passwd: RHNhLTAyMTM= diff --git a/HelmCharts/wordpress-chart/values.yaml b/HelmCharts/wordpress-chart/values.yaml new file mode 100644 index 00000000..06692eed --- /dev/null +++ b/HelmCharts/wordpress-chart/values.yaml @@ -0,0 +1,82 @@ +# Default values for wordpress-chart. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: docker-registry:32000 + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "" + +imagePullSecrets: [reg-cred-secret] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + # Specifies whether a service account should be created + create: true + # Annotations to add to the service account + annotations: {} + # The name of the service account to use. + # If not set and create is true, a name is generated using the fullname template + name: "" + +podAnnotations: {} + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +service: + type: NodePort + port: 80 + +ingress: + enabled: false + className: "" + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: + - path: / + pathType: ImplementationSpecific + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + +nodeSelector: {} + +tolerations: [] + +affinity: {} diff --git a/Wordpress/kustomization.yaml b/Wordpress/kustomization.yaml index ff6ffd23..e5b094e7 100644 --- a/Wordpress/kustomization.yaml +++ b/Wordpress/kustomization.yaml @@ -1,12 +1,6 @@ -secretGenerator: -- name: mysqlwp-pass - namespace: wordpress - literals: - - password=Dsa-0213 - - db_user=root - - db_passwd=Dsa-0213 resources: - wp-namespace.yaml + - wordpress-secrets.yaml - registry-secrets.yaml - mysql-deployment.yaml - wordpress-deployment.yaml diff --git a/Wordpress/wordpress-secrets.yaml b/Wordpress/wordpress-secrets.yaml new file mode 100644 index 00000000..613d49d7 --- /dev/null +++ b/Wordpress/wordpress-secrets.yaml @@ -0,0 +1,9 @@ +apiVersion: v1 +kind: Secret +metadata: + name: mysqlwp-pass + namespace: wordpress +data: + password: RHNhLTAyMTM= + db_user: cm9vdA== + db_passwd: RHNhLTAyMTM=