<> Architecture diagram :



<> image

First of all, we will nginx and php Mirror ready , And push it to the mirror repository :
I didn't Dockerfile The files have to be able to download mine :
https://download.csdn.net/download/qq_25611295/10672202
<https://download.csdn.net/download/qq_25611295/10672202>
docker login 192.168.1.40:5000 nginx: docker build -t
192.168.1.40:5000/lnmp/nginx . docker push 192.168.1.40:5000/lnmp/nginx php:
docker bulid -t 192.168.1.40:5000/lnmp/php . docker push
192.168.1.40:5000/lnmp/php mysql: docker pull mysql:5.6 docker tag 1f47fade220d
192.168.1.40/lnmp/mysql docker push 192.168.1.40:5000/lnmp/mysql
Inspection warehouse :
Warehouse configuration :https://blog.csdn.net/qq_25611295/article/details/80967135
<https://blog.csdn.net/qq_25611295/article/details/80967135>
[[email protected] ~]# curl -u liaochao:123456 192.168.1.40:5000/v2/_catalog
{"repositories":["lnmp/mysql","lnmp/nginx","lnmp/php","nginx","php"]}
<> authentication :

After the image is ready, we need to configure some authentication files , such as ,mysql Account password for , Warehouse account password and so on , We need to put these in k8s In the certification of
mysql:
establish mysql Password authentication
kubectl create secret generic mysql-pass --from-literal=password=123456
testing :
[[email protected] LNMP]# kubectl get secret NAME TYPE DATA AGE default-token-5bjhk
kubernetes.io/service-account-token 3 24d liaochao-https kubernetes.io/tls 2 6d
mysql-pass Opaque 1 19s
Create warehouse certification :
View authentication information :(bash64 -wo On behalf of 64 Bit transcoding is displayed and does not wrap )
cat .docker/config.json |base64 -w0
Then we create the authentication based on the data :
[[email protected] LNMP]# cat docker-secret.yaml apiVersion: v1 kind: Secret
metadata: name: registrypullsecret data: .dockerconfigjson:
ewoJImF1dGhzIjogewoJCSIxOTIuMTY4LjEuNDA6NTAwMCI6IHsKCQkJImF1dGgiOiAiYkdsaGIyTm9ZVzg2TVRJek5EVTIiCgkJfQoJfSwKCSJIdHRwSGVhZGVycyI6IHsKCQkiVXNlci1BZ2VudCI6ICJEb2NrZXItQ2xpZW50LzE4LjA2LjAtY2UgKGxpbnV4KSIKCX0KfQ==
type: kubernetes.io/dockerconfigjson
establish
kubectl create -f docker-secret.yaml
testing :
[[email protected] LNMP]# kubectl get secret NAME TYPE DATA AGE default-token-5bjhk
kubernetes.io/service-account-token 3 24d liaochao-https kubernetes.io/tls 2 7d
mysql-pass Opaque 1 23m registrypullsecret kubernetes.io/dockerconfigjson 1 12s
<> to configure lnmp Environmental Science

pv data storage :
[[email protected] LNMP]# cat pv.yaml apiVersion: v1
# use glusterfs Storage , Don't you understand? glusterfs Please refer to other articles kind: PersistentVolume metadata: name:
mysql-pv spec: capacity: storage: 20Gi accessModes: - ReadWriteMany glusterfs:
endpoints: "glusterfs-cluster" path: "gv1" --- # use nfs Storage apiVersion: v1 kind:
PersistentVolume metadata: name: wp-pv spec: capacity: storage: 5Gi
accessModes: - ReadWriteMany nfs: path: /opt/container_data/wp-wwwroot server:
192.168.1.39
php to configure :
[[email protected] LNMP]# cat php-deployment.yaml apiVersion: v1 kind: Service
metadata: name: wordpress-php labels: app: wordpress spec: ports: - port: 9000
selector: app: wordpress-php tier: frontend --- apiVersion: v1 kind:
PersistentVolumeClaim metadata: name: wp-pvc labels: app: wordpress spec:
accessModes: - ReadWriteMany resources: requests: storage: 5Gi --- apiVersion:
apps/v1beta2 # for versions before 1.8.0 use apps/v1beta1 kind: Deployment
metadata: name: wordpress-php labels: app: wordpress spec: replicas: 3
selector: matchLabels: app: wordpress-php tier: frontend strategy: type:
Recreate template: metadata: labels: app: wordpress-php tier: frontend spec:
containers: - name: php image: 192.168.1.40:5000/lnmp/php ports: -
containerPort: 9000 name: wordpress volumeMounts: # be used for php Resolved directory - name:
wordpress-persistent-storage mountPath: /var/www/html ## User authentication when pulling image , Note out this when you don't have one 2 That's ok
imagePullSecrets: - name: registrypullsecret volumes: - name:
wordpress-persistent-storage persistentVolumeClaim: claimName: wp-pvc
nginx to configure :
here nginx and php Share one pv,pvc
[[email protected] LNMP]# cat nginx-deployment.yaml apiVersion: v1 kind: ConfigMap
metadata: name: nginx-wp-config data: site.conf: |- server { listen 80;
server_name localhost; root html; index index.html index.php; location ~ \.php$
{ root html; fastcgi_pass wordpress-php:9000; fastcgi_param SCRIPT_FILENAME
/var/www/html$fastcgi_script_name; include fastcgi_params;
fastcgi_connect_timeout 60s; fastcgi_read_timeout 300s; fastcgi_send_timeout
300s; } } --- apiVersion: v1 kind: Service metadata: name: wordpress-nginx
labels: app: wordpress spec: ports: - port: 80 selector: app: wordpress-nginx
tier: frontend type: NodePort sessionAffinity: ClientIP --- apiVersion:
apps/v1beta2 kind: Deployment metadata: name: wordpress-nginx labels: app:
wordpress spec: replicas: 3 selector: matchLabels: app: wordpress-nginx tier:
frontend strategy: type: Recreate template: metadata: labels: app:
wordpress-nginx tier: frontend spec: containers: - name: nginx image:
192.168.1.40:5000/lnmp/nginx ports: - containerPort: 80 name: wordpress
volumeMounts: - name: wordpress-persistent-storage mountPath:
/usr/local/nginx/html - name: config mountPath:
/usr/local/nginx/conf/vhost/site.conf subPath: site.conf imagePullSecrets: -
name: registrypullsecret volumes: - name: wordpress-persistent-storage
persistentVolumeClaim: claimName: wp-pvc - name: config configMap: name:
nginx-wp-config
yaml When the documents are ready , establish :
kubectl create -f mysql-deployment.yaml kubectl create -f php-deployment.yaml
kubectl create -f nginx-deployment.yaml
Test storage :
kubectl get pv,pvc [[email protected] lnmp]# kubectl get pv,pvc NAME CAPACITY ACCESS
MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
persistentvolume/mysql-pv 20Gi RWX Retain Bound default/mysql-pv-claim 17m
persistentvolume/wp-pv 5Gi RWX Retain Bound default/wp-pvc 2h NAME STATUS
VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
persistentvolumeclaim/mysql-pv-claim Bound mysql-pv 20Gi RWX 17m
persistentvolumeclaim/wp-pvc Bound wp-pv 5Gi RWX 2h
Detection node :( Make sure all nodes are running)
kubectl get pod -o wide
testing nginx servers Exposed ports :
kubectl get svc
And then according to nginxserver Exposed port testing nginx Is the page accessible
http://192.168.1.40:49665/ <http://192.168.1.40:49665/>
utilize phpinfo test php analysis
[[email protected] wp-wwwroot]# cat test.php <?php phpinfo(); ?>
<> deploy wordpress

Here we will nfs The mounted share path is :/opt/container_data/wp-wwwroot/
We will wordpress Put it here :
Database selection :wordpress , The host name is :wordpress-mysql, Account password selection :root 123456