mkdir -p /web/{html,data}
yum -y install nfs-utils rpcbind #安装 nfs
[root@client_15_k8s_clould ~]# cat /etc/exports
/web/html *(rw,no_root_squash)
/web/data *(rw,no_root_squash)
/ifs/kubernetes/jenkins *(rw,no_root_squash)
systemctl enable nfs && systemctl restart nfs
[root@client_15_k8s_clould h5]# showmount -e
Export list for client_15_k8s_clould:
/ifs/kubernetes/jenkins *
/web/data *
/web/html *
tar xf lnmp-v9.tar.gz
cd lnmp
unzip ecshop.zip
mv ecshop/* /web/html/
创建mysql 和 web pv
[root@client_15_k8s_clould lnmp]# cat pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: mysql-pv
labels:
apps: mysql-pv
spec:
capacity:
storage: 5Gi
accessModes:
- ReadWriteMany
nfs:
path: /web/data
server: 172.16.2.15
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: web-pv
labels:
apps: web-pv
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteMany
nfs:
path: /web/html
server: 172.16.2.15
[root@client_15_k8s_clould lnmp]# cat mysql-deployment.yaml
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql
namespace: default
labels:
k8s-app: mysql
spec:
selector:
matchLabels:
k8s-app: mysql
replicas: 1
template:
metadata:
labels:
k8s-app: mysql
spec:
containers:
- name: mysql
image: mysql:5.7
imagePullPolicy: IfNotPresent
ports:
- containerPort: 3306
protocol: TCP
volumeMounts:
- name: mysql-data
mountPath: /var/lib/mysql
env:
- name: MYSQL_ROOT_PASSWORD
value: "123456"
volumes:
- name: mysql-data
persistentVolumeClaim:
claimName: mysql-pvc
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mysql-pvc
labels:
k8s-app: mysql
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 5Gi
selector:
matchLabels:
apps: mysql-pv
---
apiVersion: v1
kind: Service
metadata:
name: mysql
labels:
k8s-app: mysql
spec:
ports:
- name: mysql
port: 3306
protocol: TCP
targetPort: 3306
selector:
k8s-app: mysql
nginx
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-shop
spec:
selector:
matchLabels:
app: nginx-shop
replicas: 1
template:
metadata:
labels:
app: nginx-shop
spec:
containers:
- name: nginx-shop
image: nginx:v1
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
volumeMounts:
- name: nginx-data
mountPath: /usr/share/nginx/html
- name: nginx-conf
mountPath: /etc/nginx/nginx.conf
subPath: nginx.conf
volumes:
- name: nginx-data
persistentVolumeClaim:
claimName: web-pvc
- name: nginx-conf
configMap:
name: lnmp-nginx-config
---
apiVersion: v1
kind: Service
metadata:
name: nginx-shop
spec:
type: NodePort
ports:
- name: nginx
port: 80
protocol: TCP
targetPort: 80
nodePort: 30010
selector:
app: nginx-shop
准备好nginx config 配置文件
kubectl create configmap lnmp-nginx-config --from-file=/root/lnmp/conf/nginx.conf -o yaml > ng-configMap.yaml
[root@client_15_k8s_clould lnmp]# cat ng-configMap.yaml
apiVersion: v1
data:
nginx.conf: |+
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
include /etc/nginx/default.d/*.conf;
location / {
index index.php;
}
location ~ \.php$ {
# root html;
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html/$fastcgi_script_name;
include fastcgi_params;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
kind: ConfigMap
metadata:
creationTimestamp: "2021-09-24T03:38:33Z"
managedFields:
- apiVersion: v1
fieldsType: FieldsV1
fieldsV1:
f:data:
.: {}
f:nginx.conf: {}
manager: kubectl
operation: Update
time: "2021-09-24T03:38:33Z"
name: lnmp-nginx-config
namespace: default
resourceVersion: "11353"
uid: 9fe6db20-ef04-45ed-b724-b8cd5c64c59a
安装php
[root@client_15_k8s_clould lnmp]# cat php-deployment.yaml
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: php-server
labels:
name: php-server
spec:
replicas: 1
selector:
matchLabels:
app: php-server
template:
metadata:
labels:
app: php-server
spec:
containers:
- name: php-server
image: php:v1
imagePullPolicy: IfNotPresent
volumeMounts:
- name: php-data
mountPath: /var/www/html/
ports:
- containerPort: 9000
lifecycle:
postStart:
exec:
command: [ "/bin/bash","-c","chown apache:apache /var/www/html -R" ]
volumes:
- name: php-data
persistentVolumeClaim:
claimName: web-pvc
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: web-pvc
labels:
app: php-server
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 1Gi
selector:
matchLabels:
apps: web-pv
---
apiVersion: v1
kind: Service
metadata:
name: php
spec:
ports:
- name: php
port: 9000
protocol: TCP
selector:
app: php-server
配置ingress