Skip to content

Instantly share code, notes, and snippets.

@geerlingguy
Last active January 29, 2024 19:43
Show Gist options
  • Save geerlingguy/e6a661e1cd2b53f6a39493ebb207425c to your computer and use it in GitHub Desktop.
Save geerlingguy/e6a661e1cd2b53f6a39493ebb207425c to your computer and use it in GitHub Desktop.
Wordpress in Kubernetes K3s on Raspberry Pi
# This manifest assumes 'wordpress' namespace is already present:
#
# kubectl create namespace wordpress
#
# Apply the manifest with:
#
# kubectl apply -f mariadb.yml
---
apiVersion: v1
kind: Secret
metadata:
name: mariadb-pass
namespace: wordpress
labels:
app: wordpress
data:
# This value is base64-encoded. Do not use this password in production!
password: MjJzaXl3dVpBNFdmeHNZcg==
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mariadb-pv-claim
namespace: wordpress
labels:
app: wordpress
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: wordpress-mariadb
namespace: wordpress
labels:
app: wordpress
spec:
selector:
matchLabels:
app: wordpress
tier: mariadb
strategy:
type: Recreate
template:
metadata:
labels:
app: wordpress
tier: mariadb
spec:
containers:
- image: tobi312/rpi-mariadb:10.3
name: mariadb
env:
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mariadb-pass
key: password
ports:
- containerPort: 3306
name: mariadb
volumeMounts:
- name: mariadb-persistent-storage
mountPath: /var/lib/mysql
resources:
limits:
cpu: '1'
memory: '512Mi'
requests:
cpu: '500m'
memory: '256Mi'
volumes:
- name: mariadb-persistent-storage
persistentVolumeClaim:
claimName: mariadb-pv-claim
---
apiVersion: v1
kind: Service
metadata:
name: wordpress-mariadb
namespace: wordpress
labels:
app: wordpress
spec:
ports:
- port: 3306
selector:
app: wordpress
tier: mariadb
clusterIP: None
# This manifest assumes 'wordpress' namespace is already present:
#
# kubectl create namespace wordpress
#
# Apply the manifest with:
#
# kubectl apply -f wordpress.yml
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: wp-pv-claim
namespace: wordpress
labels:
app: wordpress
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
---
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: wordpress:5.4-apache
name: wordpress
env:
- name: WORDPRESS_DB_HOST
value: wordpress-mariadb
- name: WORDPRESS_DB_PASSWORD
valueFrom:
secretKeyRef:
name: mariadb-pass
key: password
ports:
- containerPort: 80
name: wordpress
volumeMounts:
- name: wordpress-persistent-storage
mountPath: /var/www/html
resources:
limits:
cpu: '1'
memory: '512Mi'
requests:
cpu: '500m'
memory: '256Mi'
volumes:
- name: wordpress-persistent-storage
persistentVolumeClaim:
claimName: wp-pv-claim
---
apiVersion: v1
kind: Service
metadata:
name: wordpress
namespace: wordpress
labels:
app: wordpress
spec:
ports:
- port: 80
selector:
app: wordpress
tier: frontend
type: NodePort
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: wordpress
namespace: wordpress
spec:
rules:
- host: wordpress.10.0.100.99.nip.io
http:
paths:
- path: /
backend:
serviceName: wordpress
servicePort: 80
@raevillena
Copy link

Been cruising around the youtube episodes and made to the point that I had wordpress running. The problem is that the ingress does not route to the wordpress app.
root@master:~/wordpress# kubectl get all -n wordpress NAME READY STATUS RESTARTS AGE pod/wordpress-mariadb-54f564f668-n76xm 1/1 Running 0 24m pod/wordpress-8bbd9f77c-f4cll 1/1 Running 0 6m37s NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/wordpress NodePort 10.43.160.149 80:30957/TCP 24m service/wordpress-mariadb ClusterIP None 3306/TCP 24m NAME READY UP-TO-DATE AVAILABLE AGE deployment.apps/wordpress-mariadb 1/1 1 1 24m deployment.apps/wordpress 1/1 1 1 24m NAME DESIRED CURRENT READY AGE replicaset.apps/wordpress-mariadb-54f564f668 1 1 1 24m replicaset.apps/wordpress-5c6b9f6dd9 0 0 0 24m replicaset.apps/wordpress-8bbd9f77c 1 1 1 6m37s

@raevillena
I ran in to the same problem where everything was running but the ingress address didn't load anything. I got to looking at the ingress address and realized it's using the IP for one of Jeff's nodes from the Ingress section at the bottom of the wordpress.yml. I edited that to be one of my nodes. i ran 'kubectl delete -f mariadb.yml' and ran it again for the wordpress.yml file and also 'kubectl delete namespace wordpress' to delete the namespace and restarted the cluster. Basically I wanted to start fresh. Once back up I created the wordpress namespace again and then ran the 'kubectl apply -f mariadb.yml' and made sure it was running using the 'kubectl get nodes -n wordpress' before running the apply again on the wordpress.yml. I tracked to see when that was running and then got the ingress address which was now pointing to one of my nodes and it loaded Wordpress. Hopefully this helps you and I didn't screw up one of the commands. I'm new at this and was just following his awesome series on the pi cluster as well.

Thanks @geerlingguy for the awesome series!

I pretty much did the same thing. I forgot to update my comment on this thread for everyone. Thanks for your update.

@Nenad13
Copy link

Nenad13 commented Feb 27, 2021

Hi Jeff,

I think I have version problem with deployment of the wordpres.yml file.

Warning: extensions/v1beta1 Ingress is deprecated in v1.14+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress ingress.extensions/wordpress configured

I try to adapt wordpress.yml file accordingly in the line 90 apiVersion: extensions/v1beta1
without success. Do you have any ideas? My k3s VERSION: v1.20.2+k3s1

By the way Thank you very much for your videos on k3s on raspberry cluster and Kubernetes! Great content!

Cheers,
Nenad

@bozh0
Copy link

bozh0 commented Sep 20, 2021

Hi Nenad13, here is the last reworked version from me that I can confirm that it works:
image

@ealvesss
Copy link

ealvesss commented Apr 25, 2022

I'm newbie with k3s but everything went well here.

I have a question, how can i access wordpress in browser?

Update:
I got how to deal with it.

@br3jlm
Copy link

br3jlm commented Jun 12, 2022

Could we please have your code updated ?

@dk98174003
Copy link

/var/lib/mysql as datadir is not working - I keep trying find a solution for this.

I can mount my persistent volumne to /data no problem but the database will write to /var/lib/mysql.

Here the error message.

2022-08-04 09:56:27+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:10.3.* started.
chown: changing ownership of '/var/lib/mysql/': Operation not permitted

;o)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment