Welcome to Nginx, puis Wordpress
Rédigé par dada / 09 novembre 2018 / Aucun commentaire
Wordpress
La partie MySQL
apiVersion: v1
kind: Service
metadata:
name: wordpress-mysql
labels:
app: wordpress
spec:
ports:
- port: 3306
selector:
app: wordpress
tier: mysql
clusterIP: None
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mysql-pv-claim2
labels:
app: wordpress
spec:
storageClassName: rook-ceph-block
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 500Mi
---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: wordpress-mysql
labels:
app: wordpress
spec:
strategy:
type: Recreate
template:
metadata:
labels:
app: wordpress
tier: mysql
spec:
containers:
- image: mysql:5.6
name: mysql
env:
- name: MYSQL_ROOT_PASSWORD
value: changeme
ports:
- containerPort: 3306
name: mysql
volumeMounts:
- name: mysql-persistent-storage
mountPath: /var/lib/mysql
volumes:
- name: mysql-persistent-storage
persistentVolumeClaim:
claimName: mysql-pv-claim2
dada@k8smaster:~$ kubectl create -f mysql.yaml
default wordpress-mysql-75477bf794-89mzw 1/1 Running 1 5h38m 10.244.2.50 k8snode2 <none>
La partie PHP
apiVersion: v1
kind: Service
metadata:
name: wordpress
labels:
app: wordpress
spec:
ports:
- port: 80
selector:
app: wordpress
tier: frontend
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: wp-pv-claim
labels:
app: wordpress
spec:
storageClassName: rook-ceph-block
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 500Mi
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: wordpress
labels:
app: wordpress
spec:
strategy:
type: Recreate
template:
metadata:
labels:
app: wordpress
tier: frontend
spec:
containers:
- image: wordpress:4.6.1-apache
name: wordpress
env:
- name: WORDPRESS_DB_HOST
value: wordpress-mysql
- name: WORDPRESS_DB_PASSWORD
value: changeme
ports:
- containerPort: 80
name: wordpress
volumeMounts:
- name: wordpress-persistent-storage
mountPath: /var/www/html
volumes:
- name: wordpress-persistent-storage
persistentVolumeClaim:
claimName: wp-pv-claim
kubectl create -f wordpress.yaml
default wordpress-796698694f-sxbhb 1/1 Running 1 3h35m 10.244.2.51 k8snode2 <none>
Ce qu'il faut saisir
dada@k8smaster:~/$ kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 4d8h
my-nginx-nginx-ingress-controller LoadBalancer 10.100.45.147 192.168.0.50 80:32462/TCP,443:30337/TCP 3d5h
my-nginx-nginx-ingress-default-backend ClusterIP 10.109.228.138 <none> 80/TCP 3d5h
wordpress ClusterIP 10.102.55.203 <none> 80/TCP 6m3s
wordpress-mysql ClusterIP None <none> 3306/TCP 6h33m
dada@k8smaster:~/$ kubectl describe service wordpress
Name: wordpress
Namespace: default
Labels: app=wordpress
Annotations: <none>
Selector: app=wordpress,tier=frontend
Type: ClusterIP
IP: 10.102.55.203
Port: <unset> 80/TCP
TargetPort: 80/TCP
Endpoints: 10.244.2.61:80
Session Affinity: None
Events: <none>
Le service Ingress
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: nginx
name: nginx-ingress
spec:
backend:
serviceName: wordpress
servicePort: 80
kubectl create -f ingress.yaml
dada@k8smaster:~/$ kubectl get ingresses
NAME HOSTS ADDRESS PORTS AGE
nginx-ingress * 80 6s
dada@k8smaster:~/$ kubectl describe ingress nginx-ingress
Name: nginx-ingress
Namespace: default
Address:
Default backend: wordpress:80 (10.244.2.61:80)
Rules:
Host Path Backends
---- ---- --------
* * wordpress:80 (10.244.2.61:80)
Annotations:
kubernetes.io/ingress.class: nginx
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal CREATE 65s nginx-ingress-controller Ingress default/nginx-ingress
Normal UPDATE 30s nginx-ingress-controller Ingress default/nginx-ingress