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

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

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

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

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

# 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

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

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

你可能感兴趣的:(CI/CD,K8s,Spring,cloud,分布式,微服务,spring,cloud,spring,boot,kubernetes,k8s,Nginx部署)