Configuration storage volume nfs
-Y-utils nfs the install yum the rpcbind
## RPC services installation and service nfs
vim / etc / exports #nfs profile
/ Data / V1 10.1.1.0/24(rw,no_root_squash,no_all_squash,sync)
# to 10.1.1.0/ ip access permissions segment 24
2. Configure nginx configuration file "default.conf"
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
location / {
root /usr/share/nginx/html;
#nginx根文件地址,访问的资源都在这个文件夹里找
index index.html index.htm;
}
location ~ \.php$ {
root /usr/share/nginx/html;
#根文件地址,定义的nginx的根一样即可,同时这个地址也要和nignx一样有访问文件。
fastcgi_pass php.default.svc.cluster.local:9000;
#访问后端php的地址,用内部server的dns解析,pod怎么重启都能正常访问的到
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;
}
}
3.PHP profile "www.conf"
the listen = 0.0.0.0:9000
# to listen to all IP
4. Write the nginx yaml resource files nginx-php.yaml
apiVersion: v1
kind: Service
metadata:
name: nginx-php
namespace: default
spec:
type: NodePort
#定义类型为NodePort,用户需要访问通过node节点的30081
selector:
app: web
ports:
- port: 80
#service端口
targetPort: 80
#容器端口
nodePort: 30081
#node端口,如果是ClusterIP的这段不需要,也可以不填会随机
---
apiVersion: v1
kind: Pod
metadata:
name: ngingx-php
labels:
app: web
spec:
containers:
- name: ngingx-php
image: nginx
imagePullPolicy: IfNotPresent
volumeMounts:
- name: nginx-data
#调用存储卷,映射到"/usr/share/nginx/html"文件夹,这里面是放nginx的访问文件的
mountPath: /usr/share/nginx/html
- name: nginx-conf
#调用存储卷,映射到"/etc/nginx/conf.d"文件夹,这里面是放nginx的配置文件的
mountPath: /etc/nginx/conf.d
volumes:
- name: nginx-data
#定义Nginx访问文件存储卷
nfs:
path: /data/v1/data
server: 10.1.1.111
#存储卷是由nfs服务器10.1.1.111 提供的,"/data/v1/data"这个文件夹是真正存文件的
- name: nginx-conf
#定义Nginx配置文件存储卷
nfs:
path: /data/v1/nginx-conf
server: 10.1.1.111
5.php yaml file php.yaml
apiVersion: v1
kind: Service
metadata:
name: php
namespace: default
spec:
selector:
app: php
ports:
- port: 9000
targetPort: 9000
#由于nginx和php都是pod 内部访问就可以了暴露内部端口即可
---
apiVersion: v1
kind: Pod
metadata:
name: php
labels:
app: php
spec:
containers:
- name: php
image: phpdockerio/php56-fpm
imagePullPolicy: IfNotPresent
volumeMounts:
- name: php-conf
#调用php配置存储卷
mountPath: /etc/php5/fpm/pool.d
- name: php-data
#调用nginx的存储文件夹,php也要一份nginx的访问文件,没有调用过来是无文件处理
mountPath: /usr/share/nginx/html
volumes:
- name: php-conf
nfs:
path: /data/v1/php-conf
server: 10.1.1.111
- name: php-data
nfs:
path: /data/v1/data
server: 10.1.1.111
6.php test file "info.php"
<?php
phpinfo();
?>
7. Access
# 30081 to find a node of port access http://10.1.1.111:30081/info.php