陈奇网络工作室

如何在k8s上部署nginx?

建设工作站服务器

k8s启动nginx服务

这次需要启动在nginx上实现的静态文件服务器。

创建命名空间脚本create_shjujubu_namespace.yaml

MT4教程专题http://www.gendan5. com/operation.html

apiVersion: v1

kind: Namespace

元数据:

name: shujubu

labels :

name: shujubu

执行文件创建shujubu命名空间:

kubectlcreate-fcreate _ shjujubu _ namespace.YAML

1

所需的镜像列表:

nginx 1.1762 c 261073 ECF3months ago 109 MB

1

定义pod文件nginx-pod.yaml

apiVersion: v1

kind: Pod

元数据:

name: sjb-nginx

namespace: shujubu

labels :

name: sjb-nginx

spec :

containers :

name:nginx

image:CCR.CCS.Tencent yun.com/shujubu/nginx:1.17

imagePullPolicy: IfNotPresent

端口:

container port:80

volumeMounts :

mount path:/etc/nginx/nginx.conf

name: config

mount path:/etc/nginx/conf.d/default.conf

name: default

mount path:/var/log/nginx /

name: log

mount path:/usr/share/nginx/shzr/area

name: shzr

mount path:/usr/share/nginx/zgbs/mujun

name: mujun

mount path:/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配置文件、日志文件和要访问的资源文件。

定义服务文件nginx-np.yaml

apiVersion: v1

kind :服务

元数据:

name: nginx

spec :

选择器:

name: sjb-nginx

type: NodePort

端口:

protocol:TCP

端口: 10008

目标端口: 80

节点端口: 30008

请注意,服务的选择器配置与pod上的标签一致。

附上nginx.conf的部分配置

用户根;

工作器_进程1;

events {

工作器_连接器1024;

}

http {

include mime.types;

efault _ type application/octet-stream;

发送文件on;

keepalive_timeout 65;

gzip on;

gzip_min_length 1024K; 大于#1m的压缩

gzip_comp_level 5; #压缩级别1-10的数字越大,压缩越好

GIP _ types text/plain application/x-JavaScript text/CSS application/XML application/JSON text/JavaScript application

服务器{

listen 80

server_name 192.168.111.36:80;

位置/{

root /usr/share/nginx/html;

index index.html;

}

error _ page 500502503504/50x.html;

location=/50x.html {

root /usr/share/nginx/html;

}

location ^~ /shzr/area/{

root /usr/share/nginx/

自动索引on;

}

location ^~ /zgbs/mujun/{

root /usr/share/nginx/

自动索引on;

}

location ^~ /zgbs/area/{

root /usr/share/nginx/

自动索引on;

}

}

}

启动pod命令:

ubectlcreate-f nginx-pod.YAML-nshujubu

1

启动服务命令:

ubectlcreate-f nginx-NP.YAML-nshujubu

详情请访问云服务器、域名注册、虚拟主机的问题,请访问西部数码代理商官方网站: www.chenqinet.cn

相关推荐

后台-系统设置-扩展变量-手机广告位-内容页底部广告位3