一看必会系列:k8s 练习33 wordpress php nginx mysql 全家桶部署

来源:本站原创 Kubernetes 超过30 views围观 0条评论

来搞一套完整的PHP MYSQL INGRESS 在K8S上的部署教程

组件PHP WORDPRESS
MYSQL
INGRESS
K8S
DOCKER

一。建mysql rc 与sr 服务

创建RC
[root@master yaml]# cat mysql-rc.yaml
apiVersion: v1
kind: ReplicationController
metadata:
  name: mysql-rc
  labels:
    name: mysql-pod-lb
spec:
  replicas: 1
  selector:
    name: mysql-pod-lb
  template:
    metadata:
      labels:
        name: mysql-pod-lb
    spec:
     containers:
     – name: mysql-name
       image: daocloud.io/library/mysql:5.7.4
       ports:
       – containerPort: 3306
       env:   #密码一定要不然报错
       – name: MYSQL_ROOT_PASSWORD
         value: "mysql"
       volumeMounts:    #本地卷 挂载到容器内的数据目录 /var/lib/mysql
       – mountPath: /var/lib/mysql
         name: mysqldata
     volumes:     #创建本地卷,将数据挂到本地,数据持久化
      – name: mysqldata
        hostPath:
          path: /data/mysql_data

创建service
[root@master yaml]# cat mysql-svc.yaml
apiVersion: v1                                                                             
kind: Service
metadata:                                                                                  
  name: mysql-svc                                                                              
  labels:
    name: mysql-svc-lb
spec:                                                                                      
  type: NodePort
  ports:
    – port: 3306
      nodePort: 30013
  selector:
    name: mysql-pod-lb

2  生成mysql

  503  kubectl apply -f mysql-rc.yaml
  506  kubectl apply -f mysql-svc.yaml

验证
[root@master yaml]# kubectl get pod -o wide |grep mysql
mysql-rc-hjtth          1/1     Running       0          34m     92.68.111.13    slave002   <none>           <none>
#可以直接进容器进行验证服务是否起来

[root@master yaml]# kubectl get svc |grep mysql
mysql-svc      NodePort    10.109.223.210   <none>        3306:30013/TCP   33m
[root@master yaml]#
[root@master yaml]# kubectl get rc |grep mysql
mysql-rc      1         1         1       35m
[root@master yaml]#

到目NODE 上查看目录是否生成
[root@slave002 ~]# !ll
ll /data/mysql_data/
total 188440
-rw-rw—-. 1 polkitd input       56 Aug 11 05:23 auto.cnf
-rw-rw—-. 1 polkitd input 79691776 Aug 11 05:52 ibdata1
-rw-rw—-. 1 polkitd input 50331648 Aug 11 05:52 ib_logfile0
-rw-rw—-. 1 polkitd input 50331648 Aug 11 05:23 ib_logfile1
-rw-rw—-. 1 polkitd input 12582912 Aug 11 05:23 ibtmp1
drwx——. 2 polkitd input     4096 Aug 11 05:23 mysql
-rw-rw—-. 1 polkitd input        2 Aug 11 05:23 mysql-rc-hjtth.pid
drwx——. 2 polkitd input     4096 Aug 11 05:23 performance_schema
drwx——. 2 polkitd input     4096 Aug 11 05:46 wordpress
[root@slave002 ~]#

二 创建 wordpress 应用

1.创建RC
[root@master yaml]# cat wordpress-rc.yaml
apiVersion: v1
kind: ReplicationController
metadata:
  name: wp-rc
  labels:
    name: wp-pod-lb
spec:
  replicas: 1
  selector:
    name: wp-pod-lb
  template:
    metadata:
      labels:
        name: wp-pod-lb
    spec:
     containers:
     – name: wp-name
       image: daocloud.io/daocloud/dao-wordpress:latest
       ports:
       – containerPort: 80
2.创建service
[root@master yaml]# cat wordpress-svc.yaml
apiVersion: v1                                                                             
kind: Service
metadata:                                                                                  
  name: wp-svc                                                                              
  labels:
    name: wp-svc-lb
spec:                                                                                      
  type: NodePort
  ports:
    – port: 80
      nodePort: 30012
  selector:
    name: wp-pod-lb
[root@master yaml]#

三 创建 ingress 进行入站转发

[root@master yaml]# cat wordpress-ingress.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-wp
spec:
  rules:
  – host: wp.ccie.wang   #提前做域名解析
    http:
      paths:
      – path: /
        backend:
          serviceName: wp-svc
                  #这里是上面服务的端口用kubectl get pods 进行查看
                  #意思是将请求转发到 frontend-svc 的80端口,和nginx 的upstream 一样
          servicePort: 80
[root@master yaml]#

四, WORDPRESS  应用初始化

1 访问http://wp.ccie.wang/  进入初始化页面
2 输入MYSQL 信息

usrname root
password mysql
host    mysql-rc (这里写rc的名字即可)
数据库  wordpress (需要提前建立)

密码

root
root!k8$-Mysql

进入容器修改mysql权限

[root@slave002 ~]# docker ps |grep mysql
8c259e35def5        aa5364eb3d85                         "/entrypoint.sh mysq…"   10 minutes ago      Up 10 minutes                           k8s_mysql-name_mysql-rc-hjtth_default_ae1b949b-bc19-11e9-8452-000c2958de12_0
2ac851ecc85c        k8s.gcr.io/pause:3.1                 "/pause"                 10 minutes ago      Up 10 minutes                           k8s_POD_mysql-rc-hjtth_default_ae1b949b-bc19-11e9-8452-000c2958de12_0
[root@slave002 ~]#

进入
[root@slave002 ~]# docker  exec -it 8c259e35def5 /bin/bash
进入mysql
root@mysql-rc-hjtth:/usr/local/mysql# mysql -u root -pmysql
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.7.4-m14 MySQL Community Server (GPL)

#修改权限
mysql> SET PASSWORD FOR `root`@`%` = PASSWORD(‘********d’);

CREATE DATABASE `wordpress` CHARACTER SET ‘utf8’ COLLATE ‘utf8_bin’;

验证

1,先发一篇文章 k8s 练习33 k8s wordpress nginx mysql 部署

2。进行验证,成功
[root@master yaml]# curl http://wp.ccie.wang/ -s |grep 练习33  |tail -n 1
                <a href="http://wp.ccie.wang/2019/08/11/k8s-%e7%bb%83%e4%b9%a033-k8s-wordpress-nginx-mysql-%e9%83%a8%e7%bd%b2/">k8s 练习33 k8s wordpress nginx mysql 部署</a>

成功 一套完整的PHP MYSQL INGRESS 就完成了

文章出自:CCIE那点事 http://www.jdccie.com/ 版权所有。本站文章除注明出处外,皆为作者原创文章,可自由引用,但请注明来源。 禁止全文转载。
本文链接:http://www.jdccie.com/?p=4184转载请注明转自CCIE那点事
如果喜欢:点此订阅本站
  • 相关文章
  • 为您推荐
  • 各种观点