k8s 小实验nginx+php
1.配置nfs 存储卷
yum -y install nfs-utils rpcbind
##安装nfs服务和RPC服务
vim /etc/exports #nfs的配置文件
/data/v1 10.1.1.0/24(rw,no_root_squash,no_all_squash,sync)
#给10.1.1.0/24网段的ip 访问的权限
2.配置nginx的配置文件"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配置文件"www.conf"
listen = 0.0.0.0:9000
#监听所有IP
4.编写nginx的yaml 资源文件 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文件 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 测试文件 "info.php"
<?php phpinfo(); ?>
7.访问
#找个node 的 30081端口访问 http://10.1.1.111:30081/info.php
相关推荐
88427810 2020-11-02
kunyus 2020-10-28
hubanbei00的家园 2020-10-25
btqszl 2020-10-21
XiaoMuFireAnt 2020-09-02
shurenyun 2020-08-19
CurrentJ 2020-08-18
hegaoye0 2020-08-18
WFMoonlight 2020-08-17
xiunai 2020-08-02
技术积累LZ 2020-07-28
lilygg 2020-07-22
akcsdno 2020-07-21
winc 2020-07-05
Dannyvon 2020-07-04
###host字段指定授权使用该证书的etcd节点IP或子网列表,需要将etcd集群的3个节点都添加其中。cp etcd-v3.3.13-linux-amd64/etcd* /opt/k8s/bin/
xiunai 2020-07-04
hevenue 2020-06-28
xiunai 2020-06-28
ajuan 2020-06-25