# apt-get 方式安装
apt-get install nfs-kernel-server
# 启动并设置开机自动启动
systemctl enable rpcbind
systemctl enable nfs-kernel-server
systemctl start rpcbind
systemctl start nfs-kernel-server
# yum 方式安装
yum -y install nfs-utils rpcbind
# 启动并设置开机自动启动
systemctl enable rpcbind
systemctl enable nfs
systemctl start rpcbind
systemctl start nfs
cat < /etc/exports
/usr/share/nginx/html/
EOF
systemctl restart nfs-kernel-server # ubuntu重启方式
systemctl restart nfs # centos重启方式
切换登录其他 node 从机查看
[root@master1 ~/Yii]#showmount -e nfs.myit.icu
Export list for nfs.myit.icu:
/data/nfsData/Yii 42.51.0.0/16
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html/frontend/web;
index index.php index.html index.htm;
try_files $uri $uri/ /index.php$is_args$args;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
root /usr/share/nginx/html/frontend/web;
fastcgi_pass unix:/run/php/php7.3-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html/backend/web;
index index.php index.html index.htm;
try_files $uri $uri/ /index.php$is_args$args;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
root /usr/share/nginx/html/backend/web;
fastcgi_pass unix:/run/php/php7.3-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
apiVersion: v1
kind: ReplicationController
metadata:
name: frontend
spec:
replicas: 1
selector:
app: frontend
template:
metadata:
labels:
app: frontend
spec:
containers:
- name: frontend
image: lnmp:7.3
imagePullPolicy: IfNotPresent
resources:
requests:
memory: 64Mi
cpu: 100m
limits:
memory: 128Mi
cpu: 200m
livenessProbe:
exec:
command:
- "/etc/init.d/php7.3-fpm"
- "start"
ports:
- containerPort: 80
volumeMounts:
- name: code
mountPath: /usr/share/nginx/html/
- name: config
mountPath: /etc/nginx/conf.d/
volumes:
- name: code
nfs:
server: nfs.myit.icu
path: /data/nfsData/Yii/advanced
- name: config
configMap:
name: frontend
items:
- key: "frontend.conf"
path: "frontend.conf"
apiVersion: v1
kind: ReplicationController
metadata:
name: backend
spec:
replicas: 1
selector:
app: backend
template:
metadata:
labels:
app: backend
spec:
containers:
- name: backend
image: lnmp:7.3
imagePullPolicy: IfNotPresent
resources:
requests:
memory: 64Mi
cpu: 100m
limits:
memory: 128Mi
cpu: 200m
livenessProbe:
exec:
command:
- "/etc/init.d/php7.3-fpm"
- "start"
ports:
- containerPort: 80
volumeMounts:
- name: code
mountPath: /usr/share/nginx/html/
- name: config
mountPath: /etc/nginx/conf.d/
volumes:
- name: code
nfs:
server: nfs.myit.icu
path: /data/nfsData/Yii/advanced
- name: config
configMap:
name: backend
items:
- key: "backend.conf"
path: "backend.conf"
vim advanced-svc.yaml
apiVersion: v1
kind: Service
metadata:
name: frontend-service
labels:
app: frontend
spec:
type: NodePort
ports:
- name: frontend
port: 80
nodePort: 30080
selector:
app: frontend
---
apiVersion: v1
kind: Service
metadata:
name: backend-service
labels:
app: backend
spec:
type: NodePort
ports:
- name: backend
port: 80
nodePort: 30081
selector:
app: backend
# ConfigMap
[root@master1 ~/Yii]#kubectl create configmap frontend --from-file=frontend.conf
configmap/frontend created
[root@master1 ~/Yii]#kubectl create configmap backend --from-file=backend.conf
configmap/backend created
# ReplicationController
[root@master1 ~/Yii]#kubectl apply -f frontend-rc.yaml
replicationcontroller/frontend created
[root@master1 ~/Yii]#kubectl apply -f backend-rc.yaml
replicationcontroller/backend created
[root@master1 ~/Yii]#vim advanced-svc.yaml
# Service
[root@master1 ~/Yii]#kubectl apply -f advanced-svc.yaml
service/frontend-service created
service/backend-service created
kubectl autoscale rc frontend-rc --min=1 --max=10 --cpu-percent=50
kubectl autoscale rc backend-rc --min=1 --max=10 --cpu-percent=50
默认监测时间:30s master 检测到项目容器 cpu 使用率上升至 50% 以上时,自动扩充容器数量 master 检测到项目容器 cpu 使用率下降至 50% 以下时,自动缩减容器数量
注意:最后由于网站代码问题,所以访问不成功,然后我又放入了一套php源码,测试是没问题的