栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

2021-10-21

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

2021-10-21

要把一个h5的文件夹做成个镜像然后部署
  1. 首先整个空文件夹,把h5文件放进去,写个dockerfile

    mkdir test-h5
    cd test-h5/
    vim Dockerfile
      FROM nginx:1.18.0-alpine
      RUN mkdir -p /mnt/nginx/html
      COPY ./h5 /mnt/nginx/html/h5              #./h5是要copy的文件夹  /mnt/nginx/html/h5复制文件夹到文件夹
      ENV TZ=Asia/Shanghai
      CMD ["nginx","-g","daemon off;"]          #nginx前台运行,CMD后面有空格!!!
      
      #具体还有啥命令自己百度
    
  2. 开始写deployment.yaml,service.yaml

    (参考:https://blog.csdn.net/dy1316434466/article/details/105440172)

    vim test-h5-deployment.yaml
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: test-h5
      namespace: default
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: test-h5
          group: default-app
      template:
        metadata:
          labels:
            app: test-h5
            group: default-app
        spec:
          containers:
          - name: web   
            image: test-h5:v1  #镜像
            imagePullPolicy: Always 
            resources:
              limits:
                cpu: 300m
                memory: 100Mi
              requests:
                cpu: 100m
                memory: 50Mi
            workingDir: /mnt/nginx/html
            ports:
            - name: http-port
              containerPort: 80
            livenessProbe:
              tcpSocket:
                port: http-port
              initialDelaySeconds: 5
              periodSeconds: 30
              failureThreshold: 5
            readinessProbe:
              tcpSocket:
                port: http-port
              initialDelaySeconds: 2
              periodSeconds: 5
              successThreshold: 2
              failureThreshold: 5
            volumeMounts:
            - name: test-h5
              mountPath: /etc/nginx/nginx.conf
              subPath: nginx.conf
            - name: test-h5
              mountPath: /etc/nginx/conf.d/default.conf
              subPath: test-h5.conf
            - name: log-path
              mountPath: /var/log/nginx
          hostname: test-h5
          imagePullSecrets:
          - name: [secret-name]   #自己的secret-name
          restartPolicy: Always
          volumes:
          - name: test-h5
            configMap:
              name: test-h5
              items:
              - key: nginx.conf
                path: nginx.conf
              - key: test-h5.conf
                path: test-h5.conf
          - name: log-path
            hostPath:
              path: /home/logs/test-h5
              type: DirectoryOrCreate
    
    
    vim test-h5-service.yaml
    apiVersion: v1
    kind: Service
    metadata:
      name: test-h5
    spec:
      type: NodePort
      selector:
        app: test-h5
      ports:
      - port: 80
        nodePort: 30099
        name: http-port
        targetPort: http-port
    
    
  3. 部署

     kubectl create -f ./test-h5-deployment.yaml -f ./test-h5-service.yaml
    
  4. 这个时候通过kubectl get pod 发现是在等待容器的创建

    docker images 发现镜像是存在的,那么就考虑deployment.yaml了。镜像是FROM nginx:1.18.0-alpine,需要替换nginx.conf

    vim test-h5-configmap.yaml
    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: test-h5
      namespace: default
    data:
      nginx.conf: |    
        user  root;
        worker_processes  1;
        
        error_log  /var/log/nginx/error.log warn;
        pid        /var/run/nginx.pid;    
        
        events {
            worker_connections  5000;
        }
        
        http {
            include       /etc/nginx/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  /var/log/nginx/access.log  main;
            
            sendfile        on;
            #tcp_nopush     on;
            
            keepalive_timeout  65;
            
            gzip  on;
            
            include /etc/nginx/conf.dtest-h5:v1
    docker push registry.cn-hangzhou.aliyuncs.comtest-h5:v1
    #(要记得把deployment中的镜像名称改成这个)
    

P:这个镜像是根据文件夹来的,那么岂不是文件夹每改一下,镜像就要更改一下??巴拉巴拉,等改的时候再说吧,嗐!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/338403.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号