在K8s平台部署个人博客
- 实验步骤
- 查看wordpress前端的service
- 配置word press
实验步骤
kubectl create secret generic mysql-pass --from-literal=password=YOUR_PASSWORD
把mysql.tar.gz和wordpress.tar.gz上传到K8s工作节点,手动解压即可:
通过网盘分享的文件:wordpress.tar.gz
链接: https://pan.baidu.com/s/1nISFKNIyANvcuBAWE9MAMQ?pwd=u77k 提取码: u77k
通过网盘分享的文件:mysql.tar.gz
链接: https://pan.baidu.com/s/1NVw3fULvQ3NOAAKtjU7nOw?pwd=8r2v 提取码: 8r2v
docker load -i mysql.tar.gz
docker load -i wordpress.tar.gz
ctr –n=k8s.io images import mysql.tar.gz
ctr –n=k8s.io images import wordpress.tar.gz
部署服务
cat mysql.yaml
apiVersion: v1
kind: Service
metadata:name: wordpress-mysqllabels:app: wordpress
spec:ports:- port: 3306selector:app: wordpresstier: mysqlclusterIP: None
---
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:name: wordpress-mysqllabels:app: wordpress
spec:replicas: 1selector:matchLabels:app: wordpresstier: mysqlstrategy:type: Recreatetemplate:metadata:labels:app: wordpresstier: mysqlspec:containers:- image: mysql:5.6name: mysqlenv:- name: MYSQL_ROOT_PASSWORDvalueFrom:secretKeyRef:name: mysql-passkey: passwordports:- containerPort: 3306name: mysqlvolumeMounts:- name: mysql-persistent-storagemountPath: /var/lib/mysqlvolumes:- name: mysql-persistent-storagehostPath:path: /datawordpresstype: DirectoryOrCreate
cat wordpress.yaml
apiVersion: v1
kind: Service
metadata:name: wordpresslabels:app: wordpress
spec:type: NodePortports:- port: 80nodePort: 30090selector:app: wordpresstier: frontend
---
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:name: wordpresslabels:app: wordpress
spec:selector:matchLabels:app: wordpresstier: frontendstrategy:type: Recreatetemplate:metadata:labels:app: wordpresstier: frontendspec:containers:- image: wordpress:4.8-apachename: wordpressenv:- name: WORDPRESS_DB_HOSTvalue: wordpress-mysql- name: WORDPRESS_DB_PASSWORDvalueFrom:secretKeyRef:name: mysql-passkey: passwordports:- containerPort: 80name: wordpressvolumeMounts:- name: wordpress-persistent-storagemountPath: /var/www/htmlvolumes:- name: wordpress-persistent-storagehostPath:path: /datamysqlwordpresstype: DirectoryOrCreate
kubectl apply -f mysql.yaml
kubectl apply -f wordpress.yaml
查看wordpress前端的service
kubectl get svc -l app=wordpress
配置word press
浏览器访问http://node_ip:30090