Skip to content

Commit 55c5830

Browse files
authored
Creating A Wordpress application using Kubernetes
1 parent 8e94f9c commit 55c5830

1 file changed

Lines changed: 166 additions & 0 deletions

File tree

Kubernetese/WordpressApp

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
---
2+
kind: PersitentVolumeClaim
3+
apiVersion: v1
4+
metadata:
5+
name: mysql-volumeclaim
6+
spec:
7+
accessMode:
8+
- ReadWriteOnce
9+
resources:
10+
requests:
11+
storage: 200Gi
12+
13+
#Here we are just making a claim for 200GB Volume in Read-write mode
14+
#The volume will be provisioned first, and then it will be claimed by our MySQL pod
15+
# Now we can create deployment file for our MySQL pod
16+
17+
18+
---
19+
piVersion: apps/v1
20+
kind: Deployment
21+
metadata:
22+
name: mysql
23+
labels:
24+
app: mysql
25+
spec:
26+
replicas: 1
27+
selector:
28+
matchLabels:
29+
app: mysql
30+
template:
31+
metadata:
32+
labels:
33+
app: mysql
34+
spec:
35+
containers:
36+
- image: mysql:5.6
37+
name: mysql
38+
env:
39+
- name: MYSQL_ROOT_PASSWORD
40+
valueFrom:
41+
secretKeyRef:
42+
name: mysql
43+
key: password
44+
ports:
45+
- containerPort: 3306
46+
name: mysql
47+
volumeMounts:
48+
- name: mysql-persistent-storage
49+
mountPath: /var/lib/mysql
50+
volumes:
51+
- name: mysql-persistent-storage
52+
persistentVolumeClaim:
53+
claimName: mysql-volumeclaim
54+
55+
Here we are only creating a single replica, so we don’t have any issue with our read-write volume
56+
We are passing a Environment variable in our MySQL container for its root password using a secret object.
57+
Now, if you look at our mysql-deployment.yaml you can see we are associating our persistent volume object with this deployment and then mounting it inside the MySQL container
58+
59+
Now we will create mysql-service.yaml
60+
This will create an internal service to access our MySQL deployment
61+
62+
---
63+
apiVersion: v1
64+
kind: Service
65+
metadata:
66+
name: mysql
67+
lables:
68+
app: mysql
69+
spec:
70+
type: ClusterIP
71+
ports:
72+
- port: 3306
73+
selector:
74+
app: mysql
75+
76+
We will create a persistent volume claim for our Wordpress Application
77+
78+
---
79+
kind: PersistentVolumeClaim
80+
apiVersion: v1
81+
metadata:
82+
name: wordpress-volumeclaim
83+
spec:
84+
accessModes:
85+
- ReadWriteOnce
86+
resources:
87+
requests:
88+
storage: 200Gi
89+
90+
91+
create a deployment.yaml for Wordpress application.
92+
93+
---
94+
apiVersion: apps/v1
95+
kind: Deployment
96+
metadata:
97+
name: wordpress
98+
labels:
99+
app: wordpress
100+
spec:
101+
replicas: 1
102+
selector:
103+
matchLabels:
104+
app: wordpress
105+
template:
106+
metadata:
107+
labels:
108+
app: wordpress
109+
spec:
110+
containers:
111+
- image: wordpress
112+
name: wordpress
113+
env:
114+
- name: WORDPRESS_DB_HOST
115+
value: mysql:3306
116+
- name: WORDPRESS_DB_PASSWORD
117+
valueFrom:
118+
secretKeyRef:
119+
name: mysql
120+
key: password
121+
ports:
122+
- containerPort: 80
123+
name: wordpress
124+
volumeMounts:
125+
- name: wordpress-persistent-storage
126+
mountPath: /var/www/html
127+
volumes:
128+
- name: wordpress-persistent-storage
129+
persistentVolumeClaim:
130+
claimName: wordpress-volumeclaim
131+
132+
133+
#create a service definition to expose our Wordpress Application for the outside world
134+
135+
---
136+
137+
apiVersion: v1
138+
kind: Service
139+
metadata:
140+
labels:
141+
app: wordpress
142+
name: wordpress
143+
spec:
144+
type: LoadBalancer
145+
ports:
146+
- port: 80
147+
targetPort: 80
148+
protocol: TCP
149+
selector:
150+
app: wordpress
151+
152+
153+
154+
kubectl apply -f mysql-volumeclaim.yaml -f wordpress-volumeclaim.yaml
155+
kubectl get pvc
156+
kubectl create secrete generic mysql --from-literal=password=YOURPASSWORD
157+
kubectl apply -f mysql-deployments.yaml -f mysql-service.yaml
158+
kubectl get pods
159+
kubectl get svc
160+
kubectl apply -f wordpress-deployment.yaml -f wordpress-serice.yaml
161+
kubectl get pods
162+
kubectl get svc
163+
164+
You will get public IP for your Wordpress blog copy it and past it in a new tab of browser.And you get the Wordpress initial setup tour something like this.
165+
166+
Thanks.

0 commit comments

Comments
 (0)