【业务功能129】微服务-springcloud-springboot-Kubernetes集群-k8s集群-KubeSphere部署三高微服务项目-k8s集群-09微服务前端代理服务 Nginx部署

46 篇文章 1 订阅
12 篇文章 0 订阅

k8s集群中部署微服务项目前端代理服务 Nginx

在这里插入图片描述

一、微服务项目静态资源准备

在这里插入图片描述

# mkdir sangomall-proxy
# cd sangomall-proxy/
[root@k8s-master01 sangomall-proxy]# ls
conf  Dockerfile  html  html.tar.gz
  • 创建的conf目录下,我们需要放入nginx的配置文件,这里可以这么来获取:先运行一个nginx容器,然后将安装好在默认目录下的配置文件复制过来,接着再把其nginx容器删除
cd conf/
docker run -d nginx:latest
docker ps        //查看对应安装好的nginx容器ID 用来进行下一步复制配置文件能找到对应的文件位置
docker cp 安装的nginx容器ID:/ect/nginx/conf./default.conf .
docker stop 安装的nginx容器ID; docker rm 安装的nginx容器ID
[root@k8s-master01 sangomall-proxy]# cd conf/
[root@k8s-master01 conf]# ls
default.conf
[root@k8s-master01 conf]# vim default.conf
[root@k8s-master01 conf]# cat default.conf

upstream sangomall {
      server mall-gateway.sangomall.svc.cluster.local.:8072;
    }

server {
    listen       80;
    server_name  *.msb.com;

    #access_log  /var/log/nginx/host.access.log  main;


    location /static/ {
       root   /usr/share/nginx/html;
    }


    location / {
       proxy_set_header Host $host;
       proxy_pass http://sangomall;
    }


    #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;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}
[root@k8s-master01 sangomall-proxy]# ls
conf  Dockerfile  html  html.tar.gz
[root@k8s-master01 sangomall-proxy]# cd html
[root@k8s-master01 html]# ls
es  index.html  static
[root@k8s-master01 html]# cat es/fenci.txt
sango
mall
[root@k8s-master01 html]# cat index.html
<h1>sangomall </h1>
[root@k8s-master01 html]# ls static
cart  index  item  login  order  reg  search
[root@k8s-master01 sangomall-proxy]# cd html/
# tar czvf html.tar.gz *
[root@k8s-master01 sangomall-proxy]# mv html.tar.gz ../
[root@k8s-master01 sangomall-proxy]# vim Dockerfile
[root@k8s-master01 sangomall-proxy]# cat Dockerfile
FROM nginx

MAINTAINER nextgo@126.com

RUN rm -rf /etc/nginx/conf.d/*

COPY conf/* /etc/nginx/conf.d/


ADD html.tar.gz  /usr/share/nginx/html/

EXPOSE 80

ENTRYPOINT nginx -g "daemon off;"

二、微服务项目前端代理服务镜像制作

[root@k8s-master01 sangomall-proxy]# docker build -t docker.io/nextgomsb/nginx:v1 .
[root@k8s-master01 sangomall-proxy]# docker images
REPOSITORY                                TAG       IMAGE ID       CREATED         SIZE
nextgomsb/nginx                           v1        f83f673f91df   4 seconds ago   173MB
[root@k8s-master01 sangomall-proxy]# docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: nextgomsb
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded
[root@k8s-master01 sangomall-proxy]# docker push docker.io/nextgomsb/nginx:v1

在这里插入图片描述

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值