zoukankan      html  css  js  c++  java
  • k8s 部署应用

    更新/etc/exports并重启nfs/rpcbind服务,使之能共享新路径

    # 在master上sudo vi /etc/exports
    /home/bigcat/k8s/beiqin 192.168.121.150/24(rw,sync)
    
    sudo systemctl restart nfs.service
    sudo systemctl restart rpcbind.service
    
    # 在node1/node2上建立/usr/local/beiqin,并映射nfs目录到这里
    sudo mkdir /usr/local/beiqin
    sudo mount 192.168.121.150:/home/bigcat/k8s/beiqin /usr/local/beiqin
    

    部署db,使用sql脚本初始化db

    # beiqin-db-deploy
    
    apiVersion: apps/v1beta1
    kind: Deployment
    metadata:
      name: beiqin-db-deploy
    spec:
      replicas: 1
      template:
        metadata:
          labels:
            app: beiqin-db-deploy
        spec:
          volumes:
          - name: beiqin-db-volume
            hostPath:
              path: /usr/local/beiqin   # nfs映射的位置,存放sql脚本
                                        # 从logs中看到这个目录中的所有文件都被扫了一遍,所以最好这里只有sql一个文件。
          containers:
          - name: beiqin-db-deploy
            image: mysql:5.7
            ports:
            - containerPort: 3306
            env:
            - name: MYSQL_ROOT_PASSWORD
              value: "root"
            volumeMounts:
            - name: beiqin-db-volume
              mountPath: /docker-entrypoint-initdb.d    # 初始化脚本放到这里,就可以初始化db了
    

    验证db已经生成

    kubectl exec -it <db-pod> /bin/bash
    mysql -uroot -p
    show databases;
    show tables;
    

    部署db-service

    # beiqin-db-service
    apiVersion: v1
    kind: Service
    metadata:
      name: beiqin-db-service
      labels:
        app: beiqin-db-service
    spec:
      selector:
        app: beiqin-db-deploy
      ports:
      - port: 3310
        targetPort: 3306
    

    部署app

    # beiqin-app-deploy
    apiVersion: apps/v1beta1
    kind: Deployment
    metadata:
      name: beiqin-app-deploy
    spec:
      replicas: 3
      template:
        metadata:
          labels:
            app: beiqin-app-deploy
        spec:
          volumes:
          - name : beqin-app-volume
            hostPath:
              path: /usr/local/beiqin        # 宿主机路径,对应nfs映射的位置
          containers:
          - name: beiqin-app-deploy
            image: openjdk:8u222-jre
            command: ["/bin/sh"]
            args: ["-c","cd /usr/local/beiqin-dist;java -jar beiqin-app.jar"]
            volumeMounts:
            - name: beqin-app-volume
              mountPath: /usr/local/beiqin-dist  # 容器内挂载位置
    
    # application.yml
    server:
      port: 80
    spring:
      datasource:
        driver-class-name: com.mysql.jdbc.Driver
        url: jdbc:mysql://beiqin-db-service:3310/beiqin?useUnicode=true&characterEncoding=utf-8&useSSL=false
        username: root
        password: root
      mvc:
        favicon:
          enabled: false
    mybatis:
      mapper-locations: classpath:/mapper/*.xml
      configuration:
        map-underscore-to-camel-case: true
    

    验证app部署

    kubectl get pods -o wide
    
    NAME                                 READY   STATUS    RESTARTS   AGE   IP            NODE    NOMINATED NODE   READINESS GATES
    beiqin-app-deploy-67698c58bc-854s8   1/1     Running   0          19m   10.244.2.12   node2   <none>           <none>
    beiqin-app-deploy-67698c58bc-9gfdv   1/1     Running   0          19m   10.244.1.14   node1   <none>           <none>
    beiqin-app-deploy-67698c58bc-hjp44   1/1     Running   0          19m   10.244.2.11   node2   <none>           <none>
    beiqin-db-deploy-5cccd5fdd7-597g8    1/1     Running   0          62m   10.244.1.12   node1   <none>           <none>
    # 通过kubectl logs查看pod的输出log
    kubectl logs beiqin-app-deploy-67698c58bc-854s8
    
    # 使用curl测试app是否成功启动
    curl 10.244.2.12:80/goods?gid=1788
    

    部署app-service

    apiVersion: v1
    kind: Service
    metadata:
      name: beiqin-app-service
      labels:
        app: beiqin-app-service
    spec:
      selector:
        app: beiqin-app-deploy
      ports:
      - port: 80
        targetPort: 80
    
    使用curl测试service
    curl 10.97.185.8:80/goods?gid=1788
    

    使用rinetd映射地址

    vi /etc/rinetd.conf
    0.0.0.0 80 10.97.185.8 80
    
    # 启动rinetd
    sudo rinetd -c /etc/rinetd.conf
    
    # 在浏览器中使用master地址访问页面
    http://192.168.121.150/goods?gid=1789
    
    --------------------------- 知道的更多,不知道的也更多 ---------------------------
  • 相关阅读:
    HashMap按键排序和按值排序
    LeetCode 91. Decode Ways
    LeetCode 459. Repeated Substring Pattern
    JVM
    LeetCode 385. Mini Parse
    LeetCode 319. Bulb Switcher
    LeetCode 343. Integer Break
    LeetCode 397. Integer Replacement
    LeetCode 3. Longest Substring Without Repeating Characters
    linux-网络数据包抓取-tcpdump
  • 原文地址:https://www.cnblogs.com/mryux/p/15616305.html
Copyright © 2011-2022 走看看