一、打包镜像

  1. 通过jenkins打包镜像并上传到镜像仓库,只选版本号,不选部署环境,默认上传仓库地址为:

hub.pml.com/sail/ac-device:${imageVersion}
hub.pml.com/sail/ac-management:${imageVersion}
hub.pml.com/sail/ac-monitor:${imageVersion}
hub.pml.com/sail/ac-resource-pool:${imageVersion}
hub.pml.com/sail/ac-ztp:${imageVersion}
image.png

  1. Harbor登陆查看镜像

http://172.171.15.104/harbor/projects/15/repositories
image.png

二、生成本地文件

  1. 登陆到一台装有docker环境的机器上,拉取镜像

    1. docker pull hub.pml.com/sail/ac-device:2.0.2
    2. docker pull hub.pml.com/sail/ac-management:2.0.2
    3. docker pull hub.pml.com/sail/ac-monitor:2.0.2
    4. docker pull hub.pml.com/sail/ac-resource-pool:2.0.2
    5. docker pull hub.pml.com/sail/ac-ztp:2.0.2

    image.png

  2. 通过tar文件保存到本地

    1. docker save -o ac-device_2.0.2.tar hub.pml.com/sail/ac-device:2.0.2
    2. docker save -o ac-management_2.0.2.tar hub.pml.com/sail/ac-management:2.0.2
    3. docker save -o ac-monitor_2.0.2.tar hub.pml.com/sail/ac-monitor:2.0.2
    4. docker save -o ac-resource-pool_2.0.2.tar hub.pml.com/sail/ac-resource-pool:2.0.2
    5. docker save -o ac-ztp_2.0.2.tar hub.pml.com/sail/ac-ztp:2.0.2

    image.png

    三、准备yaml文件

    ac-device.yaml ```yaml apiVersion: v1 kind: Service metadata: name: ac-device namespace: access-controller labels: app: ac-device spec: ports:

    • port: 9901 name: service targetPort: 9901 protocol: TCP
    • port: 9911 name: debug targetPort: 9911 protocol: TCP nodePort: 30101 selector: app: ac-device type: NodePort

apiVersion: apps/v1 kind: Deployment metadata: name: ac-device namespace: access-controller labels: app: ac-device spec: replicas: 1 strategy: type: Recreate selector: matchLabels: app: ac-device template: metadata: labels: app: ac-device spec: hostAliases:

  1. - ip: 10.33.2.138
  2. hostnames:
  3. - mysql.mysql.svc.cluster.local
  4. nodeSelector:
  5. ac: node1
  6. containers:
  7. - name: ac-device
  8. image: hub.pml.com/sail/ac-device:2.0.2
  9. imagePullPolicy: IfNotPresent
  10. ports:
  11. - containerPort: 9901
  12. resources:
  13. limits:
  14. memory: 2Gi
  15. requests:
  16. memory: 500Mi
  17. env:
  18. - name: MYSQL_PASSWORD
  19. value: "ZZPass2019!"
  20. - name: LIMITS_MEMORY
  21. valueFrom:
  22. resourceFieldRef:
  23. resource: limits.memory
  24. divisor: 1Mi
  25. - name: JAVA_OPTS
  26. value: "-Xmx500m -Xdebug -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=9911 -XshowSettings:vm -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.port=12345 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.rmi.port=12345 -Djava.rmi.server.hostname=localhost -Dcom.sun.management.jmxremote.authenticate=false -Dfile.encoding=UTF8 -Ddruid.mysql.usePingMethod=false -Duser.timezone=GMT+08 -verbose:gc -XX:+PrintGCTimeStamps -XX:+PrintHeapAtGC -XX:+PrintGCDetails -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=50M -Xloggc:/var/log/jvm/gcc.log -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/log/jvm/ -XX:+PrintGCDateStamps"
  27. volumeMounts:
  28. - name: date-config
  29. mountPath: /etc/localtime
  30. - name: jvm-log
  31. mountPath: /var/log/jvm/
  32. - name: app-log
  33. mountPath: /opt/log/
  34. livenessProbe:
  35. httpGet:
  36. path: /ac/device/health-check
  37. port: 9901
  38. initialDelaySeconds: 30
  39. timeoutSeconds: 3
  40. failureThreshold: 3
  41. periodSeconds: 30
  42. readinessProbe:
  43. httpGet:
  44. path: /ac/device/health-check
  45. port: 9901
  46. initialDelaySeconds: 30
  47. timeoutSeconds: 3
  48. failureThreshold: 3
  49. periodSeconds: 30
  50. volumes:
  51. - name: date-config
  52. hostPath:
  53. path: /etc/localtime
  54. - name: jvm-log
  55. hostPath:
  56. path: /var/log/jvm/access-controller/ac-device/
  57. - name: app-log
  58. hostPath:
  59. path: /var/log/app/access-controller/ac-device/
  1. ac-management.yaml
  2. ```yaml
  3. apiVersion: v1
  4. kind: Service
  5. metadata:
  6. name: ac-management
  7. namespace: access-controller
  8. labels:
  9. app: ac-management
  10. spec:
  11. ports:
  12. - port: 9902
  13. name: service
  14. targetPort: 9902
  15. protocol: TCP
  16. - port: 9912
  17. name: debug
  18. targetPort: 9912
  19. protocol: TCP
  20. nodePort: 30102
  21. selector:
  22. app: ac-management
  23. type: NodePort
  24. ---
  25. apiVersion: apps/v1
  26. kind: Deployment
  27. metadata:
  28. name: ac-management
  29. namespace: access-controller
  30. labels:
  31. app: ac-management
  32. spec:
  33. replicas: 1
  34. strategy:
  35. type: Recreate
  36. selector:
  37. matchLabels:
  38. app: ac-management
  39. template:
  40. metadata:
  41. labels:
  42. app: ac-management
  43. spec:
  44. hostAliases:
  45. - ip: 10.33.2.138
  46. hostnames:
  47. - mysql.mysql.svc.cluster.local
  48. nodeSelector:
  49. ac: node1
  50. containers:
  51. - name: ac-management
  52. image: hub.pml.com/sail/ac-management:2.0.2
  53. imagePullPolicy: IfNotPresent
  54. ports:
  55. - containerPort: 9902
  56. resources:
  57. limits:
  58. memory: 2Gi
  59. requests:
  60. memory: 500Mi
  61. env:
  62. - name: MYSQL_PASSWORD
  63. value: "ZZPass2019!"
  64. - name: LIMITS_MEMORY
  65. valueFrom:
  66. resourceFieldRef:
  67. resource: limits.memory
  68. divisor: 1Mi
  69. - name: JAVA_OPTS
  70. value: "-Xmx500m -Xdebug -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=9912 -XshowSettings:vm -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.port=12345 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.rmi.port=12345 -Djava.rmi.server.hostname=localhost -Dcom.sun.management.jmxremote.authenticate=false -Dfile.encoding=UTF8 -Ddruid.mysql.usePingMethod=false -Duser.timezone=GMT+08 -verbose:gc -XX:+PrintGCTimeStamps -XX:+PrintHeapAtGC -XX:+PrintGCDetails -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=50M -Xloggc:/var/log/jvm/gcc.log -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/log/jvm/ -XX:+PrintGCDateStamps"
  71. volumeMounts:
  72. - name: date-config
  73. mountPath: /etc/localtime
  74. - name: jvm-log
  75. mountPath: /var/log/jvm/
  76. - name: app-log
  77. mountPath: /opt/log/
  78. livenessProbe:
  79. httpGet:
  80. path: /ac/management/health-check
  81. port: 9902
  82. initialDelaySeconds: 30
  83. timeoutSeconds: 3
  84. failureThreshold: 3
  85. periodSeconds: 30
  86. readinessProbe:
  87. httpGet:
  88. path: /ac/management/health-check
  89. port: 9902
  90. initialDelaySeconds: 30
  91. timeoutSeconds: 3
  92. failureThreshold: 3
  93. periodSeconds: 30
  94. volumes:
  95. - name: date-config
  96. hostPath:
  97. path: /etc/localtime
  98. - name: jvm-log
  99. hostPath:
  100. path: /var/log/jvm/access-controller/ac-management/
  101. - name: app-log
  102. hostPath:
  103. path: /var/log/app/access-controller/ac-management/

ac-monitor.yaml

  1. apiVersion: v1
  2. kind: Service
  3. metadata:
  4. name: ac-monitor
  5. namespace: access-controller
  6. labels:
  7. app: ac-monitor
  8. spec:
  9. ports:
  10. - port: 9903
  11. name: service
  12. targetPort: 9903
  13. protocol: TCP
  14. - port: 9913
  15. name: debug
  16. targetPort: 9913
  17. protocol: TCP
  18. nodePort: 30103
  19. selector:
  20. app: ac-monitor
  21. type: NodePort
  22. ---
  23. apiVersion: apps/v1
  24. kind: Deployment
  25. metadata:
  26. name: ac-monitor
  27. namespace: access-controller
  28. labels:
  29. app: ac-monitor
  30. spec:
  31. replicas: 1
  32. strategy:
  33. type: Recreate
  34. selector:
  35. matchLabels:
  36. app: ac-monitor
  37. template:
  38. metadata:
  39. labels:
  40. app: ac-monitor
  41. spec:
  42. hostAliases:
  43. - ip: 10.33.2.138
  44. hostnames:
  45. - mysql.mysql.svc.cluster.local
  46. nodeSelector:
  47. ac: node1
  48. containers:
  49. - name: ac-monitor
  50. image: hub.pml.com/sail/ac-monitor:2.0.2
  51. imagePullPolicy: IfNotPresent
  52. ports:
  53. - containerPort: 9903
  54. resources:
  55. limits:
  56. memory: 2Gi
  57. requests:
  58. memory: 500Mi
  59. env:
  60. - name: MYSQL_PASSWORD
  61. value: "ZZPass2019!"
  62. - name: LIMITS_MEMORY
  63. valueFrom:
  64. resourceFieldRef:
  65. resource: limits.memory
  66. divisor: 1Mi
  67. - name: JAVA_OPTS
  68. value: "-Xmx500m -Xdebug -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=9913 -XshowSettings:vm -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.port=12345 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.rmi.port=12345 -Djava.rmi.server.hostname=localhost -Dcom.sun.management.jmxremote.authenticate=false -Dfile.encoding=UTF8 -Ddruid.mysql.usePingMethod=false -Duser.timezone=GMT+08 -verbose:gc -XX:+PrintGCTimeStamps -XX:+PrintHeapAtGC -XX:+PrintGCDetails -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=50M -Xloggc:/var/log/jvm/gcc.log -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/log/jvm/ -XX:+PrintGCDateStamps"
  69. volumeMounts:
  70. - name: date-config
  71. mountPath: /etc/localtime
  72. - name: jvm-log
  73. mountPath: /var/log/jvm/
  74. - name: app-log
  75. mountPath: /opt/log/
  76. livenessProbe:
  77. httpGet:
  78. path: /ac/monitor/health-check
  79. port: 9903
  80. initialDelaySeconds: 30
  81. timeoutSeconds: 3
  82. failureThreshold: 3
  83. periodSeconds: 30
  84. readinessProbe:
  85. httpGet:
  86. path: /ac/monitor/health-check
  87. port: 9903
  88. initialDelaySeconds: 30
  89. timeoutSeconds: 3
  90. failureThreshold: 3
  91. periodSeconds: 30
  92. volumes:
  93. - name: date-config
  94. hostPath:
  95. path: /etc/localtime
  96. - name: jvm-log
  97. hostPath:
  98. path: /var/log/jvm/access-controller/ac-monitor/
  99. - name: app-log
  100. hostPath:
  101. path: /var/log/app/access-controller/ac-monitor/

ac-resource-pool.yaml

  1. apiVersion: v1
  2. kind: Service
  3. metadata:
  4. name: ac-resource-pool
  5. namespace: access-controller
  6. labels:
  7. app: ac-resource-pool
  8. spec:
  9. ports:
  10. - port: 9904
  11. name: service
  12. targetPort: 9904
  13. protocol: TCP
  14. - port: 9914
  15. name: debug
  16. targetPort: 9914
  17. protocol: TCP
  18. nodePort: 30104
  19. selector:
  20. app: ac-resource-pool
  21. type: NodePort
  22. ---
  23. apiVersion: apps/v1
  24. kind: Deployment
  25. metadata:
  26. name: ac-resource-pool
  27. namespace: access-controller
  28. labels:
  29. app: ac-resource-pool
  30. spec:
  31. replicas: 1
  32. strategy:
  33. type: Recreate
  34. selector:
  35. matchLabels:
  36. app: ac-resource-pool
  37. template:
  38. metadata:
  39. labels:
  40. app: ac-resource-pool
  41. spec:
  42. hostAliases:
  43. - ip: 10.33.2.138
  44. hostnames:
  45. - mysql.mysql.svc.cluster.local
  46. nodeSelector:
  47. ac: node1
  48. containers:
  49. - name: ac-resource-pool
  50. image: hub.pml.com/sail/ac-resource-pool:2.0.2
  51. imagePullPolicy: IfNotPresent
  52. ports:
  53. - containerPort: 9904
  54. resources:
  55. limits:
  56. memory: 2Gi
  57. requests:
  58. memory: 500Mi
  59. env:
  60. - name: MYSQL_PASSWORD
  61. value: "ZZPass2019!"
  62. - name: LIMITS_MEMORY
  63. valueFrom:
  64. resourceFieldRef:
  65. resource: limits.memory
  66. divisor: 1Mi
  67. - name: JAVA_OPTS
  68. value: "-Xmx500m -Xdebug -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=9914 -XshowSettings:vm -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.port=12345 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.rmi.port=12345 -Djava.rmi.server.hostname=localhost -Dcom.sun.management.jmxremote.authenticate=false -Dfile.encoding=UTF8 -Ddruid.mysql.usePingMethod=false -Duser.timezone=GMT+08 -verbose:gc -XX:+PrintGCTimeStamps -XX:+PrintHeapAtGC -XX:+PrintGCDetails -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=50M -Xloggc:/var/log/jvm/gcc.log -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/log/jvm/ -XX:+PrintGCDateStamps"
  69. volumeMounts:
  70. - name: date-config
  71. mountPath: /etc/localtime
  72. - name: jvm-log
  73. mountPath: /var/log/jvm/
  74. - name: app-log
  75. mountPath: /opt/log/
  76. livenessProbe:
  77. httpGet:
  78. path: /ac/resource/health-check
  79. port: 9904
  80. initialDelaySeconds: 30
  81. timeoutSeconds: 3
  82. failureThreshold: 3
  83. periodSeconds: 30
  84. readinessProbe:
  85. httpGet:
  86. path: /ac/resource/health-check
  87. port: 9904
  88. initialDelaySeconds: 30
  89. timeoutSeconds: 3
  90. failureThreshold: 3
  91. periodSeconds: 30
  92. volumes:
  93. - name: date-config
  94. hostPath:
  95. path: /etc/localtime
  96. - name: jvm-log
  97. hostPath:
  98. path: /var/log/jvm/access-controller/ac-resource-pool/
  99. - name: app-log
  100. hostPath:
  101. path: /var/log/app/access-controller/ac-resource-pool/

ac-ztp.yaml

  1. apiVersion: v1
  2. kind: Service
  3. metadata:
  4. name: ac-ztp
  5. namespace: access-controller
  6. labels:
  7. app: ac-ztp
  8. spec:
  9. ports:
  10. - port: 9905
  11. name: service
  12. targetPort: 9905
  13. protocol: TCP
  14. - port: 9915
  15. name: debug
  16. targetPort: 9915
  17. protocol: TCP
  18. nodePort: 30105
  19. selector:
  20. app: ac-ztp
  21. type: NodePort
  22. ---
  23. apiVersion: apps/v1
  24. kind: Deployment
  25. metadata:
  26. name: ac-ztp
  27. namespace: access-controller
  28. labels:
  29. app: ac-ztp
  30. spec:
  31. replicas: 1
  32. strategy:
  33. type: Recreate
  34. selector:
  35. matchLabels:
  36. app: ac-ztp
  37. template:
  38. metadata:
  39. labels:
  40. app: ac-ztp
  41. spec:
  42. hostAliases:
  43. - ip: 10.33.2.138
  44. hostnames:
  45. - mysql.mysql.svc.cluster.local
  46. nodeSelector:
  47. ac: node1
  48. containers:
  49. - name: ac-ztp
  50. image: hub.pml.com/sail/ac-ztp:2.0.2
  51. imagePullPolicy: IfNotPresent
  52. ports:
  53. - containerPort: 9905
  54. resources:
  55. limits:
  56. memory: 2Gi
  57. requests:
  58. memory: 500Mi
  59. env:
  60. - name: MYSQL_PASSWORD
  61. value: "ZZPass2019!"
  62. - name: LIMITS_MEMORY
  63. valueFrom:
  64. resourceFieldRef:
  65. resource: limits.memory
  66. divisor: 1Mi
  67. - name: JAVA_OPTS
  68. value: "-Xmx500m -Xdebug -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=9915 -XshowSettings:vm -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.port=12345 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.rmi.port=12345 -Djava.rmi.server.hostname=localhost -Dcom.sun.management.jmxremote.authenticate=false -Dfile.encoding=UTF8 -Ddruid.mysql.usePingMethod=false -Duser.timezone=GMT+08 -verbose:gc -XX:+PrintGCTimeStamps -XX:+PrintHeapAtGC -XX:+PrintGCDetails -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=50M -Xloggc:/var/log/jvm/gcc.log -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/log/jvm/ -XX:+PrintGCDateStamps"
  69. volumeMounts:
  70. - name: date-config
  71. mountPath: /etc/localtime
  72. - name: jvm-log
  73. mountPath: /var/log/jvm/
  74. - name: app-log
  75. mountPath: /opt/log/
  76. livenessProbe:
  77. httpGet:
  78. path: /ac/ztp/health-check
  79. port: 9905
  80. initialDelaySeconds: 30
  81. timeoutSeconds: 3
  82. failureThreshold: 3
  83. periodSeconds: 30
  84. readinessProbe:
  85. httpGet:
  86. path: /ac/ztp/health-check
  87. port: 9905
  88. initialDelaySeconds: 30
  89. timeoutSeconds: 3
  90. failureThreshold: 3
  91. periodSeconds: 30
  92. volumes:
  93. - name: date-config
  94. hostPath:
  95. path: /etc/localtime
  96. - name: jvm-log
  97. hostPath:
  98. path: /var/log/jvm/access-controller/ac-ztp/
  99. - name: app-log
  100. hostPath:
  101. path: /var/log/app/access-controller/ac-ztp/

ac-gateway.yaml

  1. apiVersion: networking.istio.io/v1alpha3
  2. kind: Gateway
  3. metadata:
  4. name: ac-gateway
  5. namespace: access-controller
  6. spec:
  7. selector:
  8. istio: ingressgateway
  9. servers:
  10. - port:
  11. number: 9900
  12. name: http
  13. protocol: HTTP
  14. hosts:
  15. - "*"
  16. ---
  17. apiVersion: networking.istio.io/v1alpha3
  18. kind: VirtualService
  19. metadata:
  20. name: ac-gateway
  21. namespace: access-controller
  22. spec:
  23. hosts:
  24. - "*"
  25. gateways:
  26. - ac-gateway
  27. http:
  28. - match:
  29. - uri:
  30. prefix: /ac/device
  31. route:
  32. - destination:
  33. port:
  34. number: 9901
  35. host: ac-device
  36. - match:
  37. - uri:
  38. prefix: /ac/management
  39. route:
  40. - destination:
  41. port:
  42. number: 9902
  43. host: ac-management
  44. - match:
  45. - uri:
  46. prefix: /ac/monitor
  47. route:
  48. - destination:
  49. port:
  50. number: 9903
  51. host: ac-monitor
  52. - match:
  53. - uri:
  54. prefix: /ac/resource
  55. route:
  56. - destination:
  57. port:
  58. number: 9904
  59. host: ac-resource-pool
  60. - match:
  61. - uri:
  62. prefix: /ac/ztp
  63. route:
  64. - destination:
  65. port:
  66. number: 9905
  67. host: ac-ztp

ac-ingressgateway.yaml

  1. apiVersion: v1
  2. kind: Service
  3. metadata:
  4. labels:
  5. app: istio-ingressgateway
  6. istio: ingressgateway
  7. operator.istio.io/component: IngressGateways
  8. operator.istio.io/managed: Reconcile
  9. release: istio
  10. name: ac-ingressgateway
  11. namespace: istio-system
  12. spec:
  13. externalTrafficPolicy: Cluster
  14. ports:
  15. - name: access-controller-public-port
  16. nodePort: 30100
  17. port: 9900
  18. protocol: TCP
  19. targetPort: 9900
  20. selector:
  21. app: istio-ingressgateway
  22. istio: ingressgateway
  23. sessionAffinity: None
  24. type: LoadBalancer

namespace.yaml

  1. apiVersion: v1
  2. kind: Namespace
  3. metadata:
  4. name: access-controller
  5. labels:
  6. istio-injection: enabled

四、文件移到生产环境

  1. 打包文件

    1. tar -zcvf cnos-ac.tar.gz ac/

    image.png

  2. 远程拷贝文件,密码为cdn%nf

    1. scp cnos-ac.tar.gz root@58.240.113.50:/home/2.0.2
  3. 目的机器解压文件

    1. tar -zxvf cnos-ac.tar.gz

    image.png

    五、安装服务

  4. 上传到本地镜像仓库

    1. docker load -i ac-device_2.0.2.tar
    2. docker load -i ac-management_2.0.2.ta
    3. docker load -i ac-monitor_2.0.2.tar
    4. docker load -i ac-resource-pool_2.0.2.tar
    5. docker load -i ac-ztp_2.0.2.tar

    image.png

  5. 通过kubectl安装服务

    1. kubectl apply -f namespace.yaml
    2. kubectl apply -f ac-gateway.yaml
    3. kubectl apply -f ac-ingressgateway.yaml
    4. kubectl apply -f ac-device.yaml
    5. kubectl apply -f ac-management.yaml
    6. kubectl apply -f ac-monitor.yaml
    7. kubectl apply -f ac-resource-pool.yaml
    8. kubectl apply -f ac-ztp.yaml
  6. 查看服务运行状态

image.png