工作負(fù)載
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-php
labels:
name: my-php
spec:
replicas: 1
selector:
matchLabels:
app: my-php
template:
metadata:
labels:
app: my-php
spec:
containers:
- name: my-php
image: php:7.2-fpm
volumeMounts:
- mountPath: /var/www/html/
name: nginx-data
ports:
- containerPort: 9000
volumes:
- name: nginx-data
hostPath:
path: /root/k8s/html
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-nginx
spec:
selector:
matchLabels:
app: my-nginx
replicas: 1
template:
metadata:
labels:
app: my-nginx
spec:
containers:
- name: my-nginx
image: nginx:1.8
ports:
- containerPort: 80
volumeMounts:
- name: nginx-data
mountPath: /usr/share/nginx/html
- name: nginx-conf
mountPath: /etc/nginx/conf.d/
volumes:
- name: nginx-data
hostPath:
path: /root/k8s/html
- name: nginx-conf
hostPath:
path: /root/k8s/conf
服務(wù)
apiVersion: v1
kind: Service
metadata:
name: my-php
spec:
ports:
- name: my-php
port: 9000
protocol: TCP
targetPort: 9000
selector:
app: my-php
apiVersion: v1
kind: Service
metadata:
name: my-nginx
spec:
type: NodePort
ports:
- name: my-nginx
port: 80
protocol: TCP
targetPort: 80
nodePort: 30003
selector:
app: my-nginx
nginx配置 default.conf
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;#index.php文件位置 與php服務(wù)中/var/www/html同步
index index.html index.htm index.php;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
# root html;
#try_files $uri =404;
fastcgi_pass my-php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html/$fastcgi_script_name;
include fastcgi_params;
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
set $real_script_name $1;
set $path_info $2;
}
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
nginx-example-ingess.yaml
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute # 類型為路由
metadata:
name: example-nginx # 定義名稱
namespace: default
spec:
entryPoints:
- web
routes:
- match: Host(`example.xxx.com`) # 轉(zhuǎn)發(fā)到域名咖城,同時可以映射路徑 && PathPrefix(`/notls`)
kind: Rule
services:
- name: my-nginx # 前面創(chuàng)建的 service崭庸,要綁定對應(yīng)上
port: 80
# 發(fā)布路由配置
kubectl apply -f nginx-example-ingess.yaml
修改 Host 為自己解析域名,新增nginx配置文件
cp default.conf nginxtest.conf
# server_name example.xxx.com;