一看必會系列:k8s 練習33 wordpress php nginx mysql 全家桶部署

來源:本站原創 Kubernetes 超過368 views圍觀 0條評論

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

組件PHP WORDPRESS
MYSQL
INGRESS
K8S
DOCKER

一。建mysql rc 與sr 服務

創建RC
[[email protected] 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
[[email protected] 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

驗證
[[email protected] yaml]# kubectl get pod -o wide |grep mysql
mysql-rc-hjtth          1/1     Running       0          34m     92.68.111.13    slave002   <none>           <none>
#可以直接進容器進行驗證服務是否起來

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

到目NODE 上查看目錄是否生成
[[email protected] ~]# !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
[[email protected] ~]#

二 創建 wordpress 應用

1.創建RC
[[email protected] 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
[[email protected] 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
[[email protected] yaml]#

三 創建 ingress 進行入站轉發

[[email protected] 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
[[email protected] yaml]#

四, WORDPRESS  應用初始化

1 訪問http://wp.ccie.wang/  進入初始化頁面
2 輸入MYSQL 信息

usrname root
password mysql
host    mysql-rc (這里寫rc的名字即可)
數據庫  wordpress (需要提前建立)

密碼

root
root!k8$-Mysql

進入容器修改mysql權限

[[email protected] ~]# 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
[[email protected] ~]#

進入
[[email protected] ~]# docker  exec -it 8c259e35def5 /bin/bash
進入mysql
[email protected]:/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。進行驗證,成功
[[email protected] 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.qdxgqk.live/ 版權所有。本站文章除注明出處外,皆為作者原創文章,可自由引用,但請注明來源。 禁止全文轉載。
本文鏈接:http://www.qdxgqk.live/?p=4184轉載請注明轉自CCIE那點事
如果喜歡:點此訂閱本站
  • 相關文章
  • 為您推薦
  • 各種觀點
?
?
萌宠夺宝游戏 狂欢节 股票涨跌自动分析公式 时时彩 江苏11选5前三组 手机打麻将软件作弊器 3d缩水app工具下载 基金配资是什么意思 山西11选5走势图 足彩比分直播新浪爱彩 麻将app哪个好 基金配资比例两种模式 哈尔滨按摩休闲中心 足球彩票比分伤停补时进球算吗 赛车大小走势 日本av女优性交快播电影 异域狂兽