K 8 s Vueアプリケーションの導入

2942 ワード

一、前言
前述したように、k 8 sはspring bootアプリケーションを配備し、原理は同じであり、vueフロントエンドアプリケーションを配備するのも同様のステップである:dockerミラーをパッケージ化-作成-k 8 s配備.
二、梱包
筆者はwebstorm開発ツールを使用して、コマンドをパッケージ化します.
node build/build.js 

パッケージングに成功すると、フォルダdistが生成されます.
三、鏡像を作る
  • nginxを記述する.confファイル:
  • #user  nobody;
    worker_processes  1;
    
    #error_log  logs/error.log;
    #error_log  logs/error.log  notice;
    #error_log  logs/error.log  info;
    
    #pid        logs/nginx.pid;
    
    events {
        worker_connections  1024;
    }
    
    
    http {
        include       mime.types;
        default_type  application/octet-stream;
    
        #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
        #                  '$status $body_bytes_sent "$http_referer" '
        #                  '"$http_user_agent" "$http_x_forwarded_for"';
    
        #access_log  logs/access.log  main;
    
        sendfile        on;
        #tcp_nopush     on;
    
        #keepalive_timeout  0;
        keepalive_timeout  65;
    
        #gzip  on;
    
    
        server {
            listen       32000;
            server_name  localhost;
    
            location / {
                #root   html;
                #index  index.html index.htm;
            }
    
             root /usr/vuejs/nginx/;
             index index.html;
    
    	location ~^/svr1[/\w*]*$ {
               proxy_pass http://192.168.10.11:31001;
            }
    	location ~^/svr2[/\w*]*$ {
               proxy_pass http://192.168.10.11:31002;
    	}
            location ~^/svr3[/\w*]*$ {
               proxy_pass http://192.168.10.11:31003;
            }
        }
    }
    
    

    説明:svr 1-svr 3は3つのサービス名です.
  • Dockerfile:
  • FROM nginx
    
    COPY nginx.conf /etc/nginx/nginx.conf
    
    COPY dist/ /usr/vuejs/nginx/
    
  • dockerミラー
  • を構築
    docker build –t fontApp:v1.0  .  
    

    四、k 8 s配置
  • はrcを記述する.yamlファイル:
  • apiVersion: v1
    kind: ReplicationController
    metadata:
            name: fontApp
    spec:
            replicas: 1
            selector:
                      app: fontApp
            template:
                    metadata:
                            labels:
                                    app: fontApp
                   spec:
                           containers:
                           - name: fontApp
                             image: fontApp:v1.0
                             ports:
                                     - containerPort:  32000
    
    
    
  • 作成svc.yamlファイル:
  • apiVersion: v1
    kind: Service
    metadata:
            name: fontApp
    spec:
             type: NodePort
             ports:
             - port: 32000
               nodePort: 32000 
             selector:
                      app: fontApp
    
    
  • rcの作成:
  • kubectl create -f rc.yaml .
    

    作成結果の表示:
    kubectl  get rc
    
  • svcの作成:
  • kubectl create -f svc.yaml .
    

    作成結果の表示:
    kubectl  get svc
    
  • podの表示:
  • kubectl get pod -o wide