建站服务器
k8s启动nginx服务
本次需要启动的是一个通过nginx实现的静态文件服务器。
创建命名空间脚本create_shjujubu_namespace.yaml
mt4教程专题http://www.gendan5.com/operation.html
apiversion: v1
kind: namespace
metadata:
name: shujubu
labels:
name: shujubu
执行文件创建 shujubu命名空间:
kubectl create -f create_shjujubu_namespace.yaml
1
需要的镜像列表:
nginx 1.17 62c261073ecf 3 months ago 109mb
1
定义pod文件 nginx-pod.yaml
apiversion: v1
kind: pod
metadata:
name: sjb-nginx
namespace: shujubu
labels:
name: sjb-nginx
spec:
containers:
– name: nginx
image: ccr.ccs.tencentyun.com/shujubu/nginx:1.17
imagepullpolicy: ifnotpresent
ports:
– containerport: 80
volumemounts:
– mountpath: /etc/nginx/nginx.conf
name: config
– mountpath: /etc/nginx/conf.d/default.conf
name: default
– mountpath: /var/log/nginx/
name: log
– mountpath: /usr/share/nginx/shzr/area
name: shzr
– mountpath: /usr/share/nginx/zgbs/mujun
name: mujun
– mountpath: /usr/share/nginx/zgbs/area
name: zgbs
restartpolicy: never
volumes:
– name: config
hostpath:
path: /home/users/qix/sjb_bs_source/nginx/nginx.conf
– name: default
hostpath:
path: /home/users/qix/sjb_bs_source/nginx/conf.d/default.conf
– name: log
hostpath:
path: /home/users/qix/sjb_bs_source/nginx/log/
– name: shzr
hostpath:
path: /home/users/qix/sjb_bs_source/shzr/area/
– name: mujun
hostpath:
path: /home/users/qix/sjb_bs_source/zgbs/mujun/
– name: zgbs
hostpath:
path: /home/users/qix/sjb_bs_source/zgbs/area/
上面的pod中只定义了一个容器,并在容器中挂载了nginx的配置文件、日志文件及我们要访问的资源文件。
定义service文件 nginx-np.yaml
apiversion: v1
kind: service
metadata:
name: nginx
spec:
selector:
name: sjb-nginx
type: nodeport
ports:
– protocol: tcp
port: 10008
targetport: 80
nodeport: 30008
注意,service中的selector中的配置要与pod中的labels保持一致。
并附上nginx.conf中的部分配置
user root;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
gzip_min_length 1024k; # 大于1m的压缩
gzip_comp_level 5; # 压缩级别 1-10 数字越大压缩的越好
gzip_types text/plain application/x-javascript text/css application/xml application/json text/javascript application/x-httpd-php image/jpeg image/gif image/png; # 压缩的文件类型
server {
listen 80;
server_name 192.168.111.36:80;
location / {
root /usr/share/nginx/html;
index index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ^~ /shzr/area/ {
root /usr/share/nginx/;
autoindex on;
}
location ^~ /zgbs/mujun/ {
root /usr/share/nginx/;
autoindex on;
}
location ^~ /zgbs/area/ {
root /usr/share/nginx/;
autoindex on;
}
}
}
启动pod命令:
kubectl create -f nginx-pod.yaml -n shujubu
1
启动service命令:
kubectl create -f nginx-np.yaml -n shujubu
做网站怎样让客户得到快速访问的体验设备与云服务器的区别是什么子站的域名解析了打不开自动加了这个子域名设置了的记录只能解析word一二三级标题设置 word一二三级标题怎么弄网站文件文件全部没有被加载出来微信小程序怎么更新网吧云服务器配置域名后缀.top什么意思