• TAP 文章系列-10 | 从应用感知能力谈 TAP 的约定服务


    Tanzu Application Platform (TAP),VMware 在2022年1月正式发布的新一代PaaS平台,该平台一大特色即为应用感知能力,即在应用程序CICD的过程中平台将自动感知应用程序的开发框架及开发语言,那么在应用部署的过程中平台将根据以上自动判断的信息自动将应用部署的配置中注入最佳实践,比如应用安全加固、应用监控、应用自愈等约定,这种自动化的过程在TAP我们称其为约定服务(Convention Service)。可见其最大的优势及价值为通过应用感知、控制翻转、自动注入等设计理念及技术实现,可大幅减少应用运维团队及开发团队的在部署应用时的工作负担。

    看到这里,相信您一定在思考一些问题,应用程序在 Kubernetes 上运行,应该如何遵循最佳约定,应该遵循哪些约定?

    在解答您的疑惑之前,我们先一起来看一个普遍的场景,假设需要在Kubernetes集群中启动一个Nginx的服务,我们会怎么做,如下所示应该是解题思路之一吧?

    第一步,编写nginx.yaml , 如下

    1. apiVersion: apps/v1
    2. kind: Deployment
    3. metadata:
    4. name: my-nginx
    5. spec:
    6. selector:
    7. matchLabels:
    8. run: my-nginx
    9. replicas: 1
    10. template:
    11. metadata:
    12. labels:
    13. run: my-nginx
    14. spec:
    15. containers:
    16. - name: my-nginx
    17. image: nginx
    18. ports:
    19. - containerPort: 80
    20. ---
    21. apiVersion: v1
    22. kind: Service
    23. metadata:
    24. name: my-nginx
    25. labels:
    26. run: my-nginx
    27. spec:
    28. ports:
    29. - port: 80
    30. protocol: TCP
    31. selector:
    32. run: my-nginx

    第二步,kubectl apply -f nginx.yaml

    这样,您就可以为 Kubernetes 节点中分配一个端口并在浏览器中访问 nginx。但是,看到这里一些应用运维的专家就不同意了,并大吼到这不能在生产环境中使用,并解释道:这种启动方式存在以下问题:

    • http通信根本没有加密,已经公开了

    • 由于 NodePort 将端口暴露给主机端,因此会产生主机被劫持的风险。

    • 如果在外部发布,应该创建一个 Ingress 资源对象。

    • 容器中的应用程序已经以root用户启动。

    • 没有设置资源限制,因此存在无限 CPU / 内存使用的风险。

    • 文件系统挂载应尽可能设置为只读。

    • ……

    然后,我们将以上发现的问题逐一解决编写到yaml文件中,但问题是这些设置不能为其他的容器统一设置并共用。在这种情况下,您需要在考虑其他应用程序“的特性的同时重复考虑如何优化使用最佳的推荐约定设置。您还需要了解特定框架所需的约定,即使它是像 nginx 这样的简单应用程序。

    那么有没有一种自动化的方案,能够帮助开发人员以及应用运维人员简化这一块的操作呢?

    答案当然是肯定的,让我们来深入的感受一下我们的TAP的约定服务吧!

    1.约定服务概述

    TAP的约定服务是实现“App-Aware Platform = 了解应用特性的平台”的功能之一,TAP应用感知平台根据这些应用程序特征为应用在部署过程中自动注入并设置这些最佳约定的机制。VMware认为,为在 Kubernetes 上运行的应用程序注入推荐约定应该是平台的工作,平台自动确定开发语言和框架并进入最佳约定的注入,而不是应用运维手册。

    Convention Service as App-Aware 的特点是它不仅扫描 Kubernetes 脚本的有效性,还扫描容器镜像本身,主要使用 SBoM(Software Bills of Materials),在搜索了实际应用程序使用的库及其版本之后,约定服务将自动为应用程序的配置注入最佳约定。

    ​Convention Service 在TAP Cartographer 软件供应链中的位置,如下所示,在完成CI流程后,供应链会进行平台装配的工作,并通过启动PodIntent的资源对象将约定注入至配置文件中。

    当 Supply Chain Choreographer 为工作负载创建或更新 PodIntent 时,Convention Service从包含工作负载镜像中检索 OCI 镜像元数据并将其注入在 PodIntent 中。 在所有服务器完成处理工作负载的 PodIntent 后,约定控制器使用最新版本的 PodTemplateSpec 更新 PodIntent 并设置 PodIntent.status.conditions[].status=True 其中 PodIntent.status.conditions[].type=Ready。这种状态变化向 Supply Chain Choreographer 发出 Convention Service 已完成其工作的信号。

    目前,TAP 1.1 提供以下几类约定:

    • Developer convention service

    • Spring Boot convention service

    • Application Live View convention service

    • Service intent convention service

    2体验约定服务

    2.1Developer Convention Service

    Developer Conventions是一组使您的工作负载能够支持实时热更新和调试操作的约定。 它与 Tanzu CLI Apps plug-in和 Tanzu Dev Tools for VSCode IDE extension起使用。

    Developer Conventions会修改您的工作负载以在以下任一情况下启用实时更新:

    • 您可以使用 Tanzu CLI Apps plug-in部署工作负载并包含标志 --live-update=true。

    • 您可以通过 Tanzu Dev Tools for VSCode IDE extension使用 Tanzu: Live Update Start 选项部署工作负载。

    当上述任一动作发生时,Developer Conventions约定的行为如下:

    • 在与工作负载关联的 PodTemplateSpec 上查找 apps.tanzu.vmware.com/live-update=true 注释。

    • 验证应用了约定的镜像是否包含可以实时更新的进程,即检查创建 Cloud Native Buildpacks 的镜像是否支持 Process Reloading。

    • 如满足以上两条,Developer Convention Service向 PodTemplateSpec 添加注释以修改 Knative 属性 minScale 和 maxScale ,使得 pod 的最小和最大数量为 1。这确保最终运行的 pod 在实时更新会话期间不会缩小到 0。

    满足以上条件之后,现在让我们看一下Developer Conventions的 LiveUpdate 功能,让我们通过以下两个测试,看看约定服务是如何工作的。

    • 支持进程重载的 Java Buildpack 的行为

    • 不支持进程重新加载的 NodeJS 构建包的行为

    首先,让我们看一下在 Cloud Native Buildpacks 中支持 Process Reloading的 Java Buildpacks 的行为。让我们使用以下命令创建一个工作负载,重要的参数是“–live-update = true”。

    1. tanzu apps workload create tanzu-java-web-app \
    2. --git-repo https://github.com/HugoXiao1984/tanzu-java-web-app \
    3. --git-branch main \
    4. --type web \
    5. --live-update=true \
    6. --yes

    创建工作负载后,如果您检查 PodIntent文件,则发现 minScale: 1 和 maxScale: 1,这意味着Developer Conventions已按预期自动注入。

    1. status:
    2. conditions:
    3. - lastTransitionTime: "2022-06-27T08:27:44Z"
    4. message: ""
    5. reason: Applied
    6. status: "True"
    7. type: ConventionsApplied
    8. - lastTransitionTime: "2022-06-27T08:27:44Z"
    9. message: ""
    10. reason: ConventionsApplied
    11. status: "True"
    12. type: Ready
    13. observedGeneration: 1
    14. template:
    15. metadata:
    16. annotations:
    17. apps.tanzu.vmware.com/live-update: "true"
    18. autoscaling.knative.dev/maxScale: "1"
    19. autoscaling.knative.dev/minScale: "1"
    20. boot.spring.io/actuator: http://:8081/actuator
    21. boot.spring.io/version: 2.5.13
    22. conventions.apps.tanzu.vmware.com/applied-conventions: |-
    23. developer-conventions/live-update-convention
    24. developer-conventions/add-source-image-label
    25. spring-boot-convention/spring-boot
    26. spring-boot-convention/spring-boot-graceful-shutdown
    27. spring-boot-convention/spring-boot-web
    28. spring-boot-convention/spring-boot-actuator
    29. appliveview-sample/app-live-view-connector
    30. appliveview-sample/app-live-view-appflavours
    31. appliveview-sample/app-live-view-systemproperties
    32. developer.apps.tanzu.vmware.com/image-source-digest: main/8aa9479d5355aa51588d39e04005a76609d08624
    33. developer.conventions/target-containers: workload
    34. labels:
    35. app.kubernetes.io/component: run
    36. apps.tanzu.vmware.com/workload-type: myweb
    37. carto.run/workload-name: tanzu-java-web-app
    38. conventions.apps.tanzu.vmware.com/framework: spring-boot
    39. tanzu.app.live.view: "true"
    40. tanzu.app.live.view.application.actuator.port: "8081"
    41. tanzu.app.live.view.application.flavours: spring-boot
    42. tanzu.app.live.view.application.name: demo
    43. spec:
    44. containers:
    45. - env:
    46. - name: JAVA_TOOL_OPTIONS
    47. value: -Dmanagement.endpoint.health.probes.add-additional-paths="true" -Dmanagement.endpoint.health.show-details=always
    48. -Dmanagement.endpoints.web.base-path="/actuator" -Dmanagement.endpoints.web.exposure.include=*
    49. -Dmanagement.health.probes.enabled="true" -Dmanagement.server.port="8081"
    50. -Dserver.port="8080" -Dserver.shutdown.grace-period="24s"
    51. image: index.docker.io/znluo/tanzu-java-web-app-default@sha256:d1fce7c186233920c697ca1722e17fd86db2151e27c1af0534378c5d27ca1371
    52. name: workload
    53. ports:
    54. - containerPort: 8080
    55. protocol: TCP
    56. resources: {}
    57. securityContext:
    58. runAsUser: 1000
    59. serviceAccountName: default

    接下来,我们来看看Cloud Native Buildpacks 中不支持Process Reloading 的 NodeJS Buildpacks 的行为。让我们使用以下命令创建一个工作负载。同样重要的是“–live-update = true”参数。

    1. tanzu apps workload create tanzu-nodejs-web-app \
    2. --git-repo https://github.com/HugoXiao1984/nodejs-hello-world \
    3. --git-branch master \
    4. --type web \
    5. --live-update=true \
    6. --yes

    创建工作负载后,当检查 Kubernetes Yaml时,minScale / maxScale 并没有被自动注入。虽然标签为apps.tanzu.vmware.com/live-update=true,但Convention Service 检测到镜像中的SBoM 不支持Process Reloading。因此,未设置 minScale / maxScale,但这也是预期的行为。

    1. status:
    2. conditions:
    3. - lastTransitionTime: "2022-06-27T09:42:12Z"
    4. message: ""
    5. reason: Applied
    6. status: "True"
    7. type: ConventionsApplied
    8. - lastTransitionTime: "2022-06-27T09:42:12Z"
    9. message: ""
    10. reason: ConventionsApplied
    11. status: "True"
    12. type: Ready
    13. observedGeneration: 1
    14. template:
    15. metadata:
    16. annotations:
    17. apps.tanzu.vmware.com/live-update: "true"
    18. conventions.apps.tanzu.vmware.com/applied-conventions: developer-conventions/add-source-image-label
    19. developer.apps.tanzu.vmware.com/image-source-digest: master/a837c6c25edc412fedcc501a4e6fef50d878adb5
    20. developer.conventions/target-containers: workload
    21. labels:
    22. app.kubernetes.io/component: run
    23. apps.tanzu.vmware.com/workload-type: myweb
    24. carto.run/workload-name: tanzu-nodejs-web-app
    25. spec:
    26. containers:
    27. - env:
    28. - name: JAVA_TOOL_OPTIONS
    29. value: -Dmanagement.endpoint.health.probes.add-additional-paths="true" -Dmanagement.health.probes.enabled="true"
    30. image: index.docker.io/znluo/tanzu-nodejs-web-app-default@sha256:8efdc874bf8251d0eee9cdf75f67ccb29a1653e7e64bf62db2e095a91f9122b6
    31. name: workload
    32. resources: {}
    33. securityContext:
    34. runAsUser: 1000
    35. serviceAccountName: default

    如本演示所示,Developer Conventions Service 检测镜像是否基于 Cloud Native Buildpacks Java / NodeJS,。平台透明地自动注入了根据应用程序自身特征的推荐约定。

    2.2 Spring Boot Convention Service

    2.2.1 Spring Boot convention

    如果依赖项下的 SBOM 文件的元数据中存在以下任何依赖项,则 Spring Boot Convention将应用于 PodTemplateSpec 对象:

    • spring-boot

    Spring Boot Convention在 PodTemplateSpec 中添加一个标签 (conventions.apps.tanzu.vmware.com/framework: spring-boot) 来描述与工作负载相关的框架,并添加一个注解 (boot.spring.io/version: VERSION-NO) 描述依赖项的 Spring Boot 版本。

    应用约定后的 PodIntent 示例:

    1. apiVersion: conventions.apps.tanzu.vmware.com/v1alpha1
    2. kind: PodIntent
    3. metadata:
    4. annotations:
    5. kubectl.kubernetes.io/last-applied-configuration: |
    6. {"apiVersion":"conventions.apps.tanzu.vmware.com/v1alpha1","kind":"PodIntent","metadata":{"annotations":{},"name":"spring-sample","namespace":"default"},"spec":{"template":{"spec":{"containers":[{"image":"springio/petclinic","name":"workload"}]}}}}
    7. ...
    8. status:
    9. conditions:
    10. - lastTransitionTime: "..." # This status indicates that all worked as expected
    11. status: "True"
    12. type: ConventionsApplied
    13. - lastTransitionTime: "..."
    14. status: "True"
    15. type: Ready
    16. observedGeneration: 1
    17. template:
    18. metadata:
    19. annotations:
    20. boot.spring.io/version: 2.3.3.RELEASE
    21. conventions.apps.tanzu.vmware.com/applied-conventions: |-
    22. spring-boot-convention/spring-boot
    23. labels:
    24. conventions.apps.tanzu.vmware.com/framework: spring-boot
    25. spec:
    26. containers:
    27. - image: index.docker.io/springio/petclinic@sha256:...
    28. name: workload
    29. resources: {}

    2.2.2 Spring boot graceful shut down convention

    如果依赖项下的 SBOM 文件的元数据中存在以下任何依赖项,则将 Spring Boot graceful shut down约定应用于 PodTemplateSpec 对象:

    • spring-boot-starter-tomcat

    • spring-boot-starter-jetty

    • spring-boot-starter-reactor-netty

    • spring-boot-starter-undertow

    • tomcat-embed-core

    Graceful Shutdown Convention spring-boot-graceful-shutdown 在环境变量 JAVA_TOOL_OPTIONS 中添加一个带有 key server.shutdown.grace-period 的属性。 .target.Spec.TerminationGracePeriodSeconds 中设置的值的 80%, .target.Spec.TerminationGracePeriodSeconds 的默认值为 30 秒。

    应用约定后的 PodIntent 示例:

    1. apiVersion: conventions.apps.tanzu.vmware.com/v1alpha1
    2. kind: PodIntent
    3. metadata:
    4. annotations:
    5. kubectl.kubernetes.io/last-applied-configuration: |
    6. {"apiVersion":"conventions.apps.tanzu.vmware.com/v1alpha1","kind":"PodIntent","metadata":{"annotations":{},"name":"spring-sample","namespace":"default"},"spec":{"template":{"spec":{"containers":[{"image":"springio/petclinic","name":"workload"}]}}}}
    7. ...
    8. status:
    9. conditions:
    10. - lastTransitionTime: "..." # This status indicates that all worked as expected
    11. status: "True"
    12. type: ConventionsApplied
    13. - lastTransitionTime: "..."
    14. status: "True"
    15. type: Ready
    16. observedGeneration: 1
    17. template:
    18. metadata:
    19. annotations:
    20. boot.spring.io/version: 2.3.3.RELEASE
    21. conventions.apps.tanzu.vmware.com/applied-conventions: |-
    22. spring-boot-convention/spring-boot
    23. spring-boot-convention/spring-boot-graceful-shutdown
    24. labels:
    25. conventions.apps.tanzu.vmware.com/framework: spring-boot
    26. spec:
    27. containers:
    28. - env:
    29. - name: JAVA_TOOL_OPTIONS
    30. value: -Dserver.shutdown.grace-period="24s"
    31. image: index.docker.io/springio/petclinic@sha256:...
    32. name: workload
    33. resources: {}

    2.2.3 Spring Boot Web convention

    如果依赖项下的 SBOM 文件的元数据中存在以下任何依赖项,则 Spring Boot Web convention将应用于 PodTemplateSpec 对象:

    • spring-boot

    • spring-boot-web

    Web 约定 spring-boot-web 从 JAVA_TOOL_OPTIONS 环境变量中获取 server.port 属性,并将其设置为 PodTemplateSpec 中的端口。 如果 JAVA_TOOL_OPTIONS 环境变量不包含 server.port 属性或值,则约定添加该属性并将值设置为 Spring Boot 的默认值8080。

    应用约定后的 PodIntent 示例:

    1. apiVersion: conventions.apps.tanzu.vmware.com/v1alpha1
    2. kind: PodIntent
    3. metadata:
    4. annotations:
    5. kubectl.kubernetes.io/last-applied-configuration: |
    6. {"apiVersion":"conventions.apps.tanzu.vmware.com/v1alpha1","kind":"PodIntent","metadata":{"annotations":{},"name":"spring-sample","namespace":"default"},"spec":{"template":{"spec":{"containers":[{"image":"springio/petclinic","name":"workload"}]}}}}
    7. ...
    8. status:
    9. conditions:
    10. - lastTransitionTime: "..." # This status indicates that all worked as expected
    11. status: "True"
    12. type: ConventionsApplied
    13. - lastTransitionTime: "..."
    14. status: "True"
    15. type: Ready
    16. observedGeneration: 1
    17. template:
    18. metadata:
    19. annotations:
    20. boot.spring.io/version: 2.3.3.RELEASE
    21. conventions.apps.tanzu.vmware.com/applied-conventions: |-
    22. spring-boot-convention/spring-boot
    23. spring-boot-convention/spring-boot-web
    24. labels:
    25. conventions.apps.tanzu.vmware.com/framework: spring-boot
    26. spec:
    27. containers:
    28. - env:
    29. - name: JAVA_TOOL_OPTIONS
    30. value: -Dserver.port="8080"
    31. image: index.docker.io/springio/petclinic@sha256:...
    32. name: workload
    33. ports:
    34. - containerPort: 8080
    35. protocol: TCP
    36. resources: {}

    2.2.4 Spring Boot Actuator convention

    如果依赖项下的 SBOM 文件的元数据中存在以下任何依赖项,则 Spring Boot Actuator convention将应用于 PodTemplateSpec 对象:

    • spring-boot-actuator

    Spring Boot Actuator convention 执行以下操作:

    • 将 JAVA_TOOL_OPTIONS 环境变量中的管理端口设置为 8081。

    • 将 JAVA_TOOL_OPTIONS 环境变量中的基本路径设置为 /actuator。

    • 在访问Actuator的位置添加注释 boot.spring.io/actuator。

    应用约定后的 PodIntent 示例:

    1. apiVersion: conventions.apps.tanzu.vmware.com/v1alpha1
    2. kind: PodIntent
    3. metadata:
    4. annotations:
    5. kubectl.kubernetes.io/last-applied-configuration: |
    6. {"apiVersion":"conventions.apps.tanzu.vmware.com/v1alpha1","kind":"PodIntent","metadata":{"annotations":{},"name":"spring-sample","namespace":"default"},"spec":{"template":{"spec":{"containers":[{"image":"springio/petclinic","name":"workload"}]}}}}
    7. ...
    8. status:
    9. conditions:
    10. - lastTransitionTime: "..." # This status indicates that all worked as expected
    11. status: "True"
    12. type: ConventionsApplied
    13. - lastTransitionTime: "..."
    14. status: "True"
    15. type: Ready
    16. observedGeneration: 1
    17. template:
    18. metadata:
    19. annotations:
    20. boot.spring.io/actuator: http://:8080/actuator
    21. boot.spring.io/version: 2.3.3.RELEASE
    22. conventions.apps.tanzu.vmware.com/applied-conventions: |-
    23. spring-boot-convention/spring-boot
    24. spring-boot-convention/spring-boot-web
    25. spring-boot-convention/spring-boot-actuator
    26. labels:
    27. conventions.apps.tanzu.vmware.com/framework: spring-boot
    28. spec:
    29. containers:
    30. - env:
    31. - name: JAVA_TOOL_OPTIONS
    32. value: Dmanagement.endpoints.web.base-path="/actuator" -Dmanagement.server.port="8081" -Dserver.port="8080"
    33. image: index.docker.io/springio/petclinic@sha256:...
    34. name: workload
    35. ports:
    36. - containerPort: 8080
    37. protocol: TCP
    38. resources: {}

    2.2.5 Spring Boot Actuator Probes convention

    在满足以下所有条件时, Spring Boot Actuator Probes convention将会被应用:

    • spring-boot-actuator 依赖存在且版本>= 2.6

    • JAVA_TOOL_OPTIONS 环境变量不包含以下属性,或者,如果包含其中任何一个属性,则将其设置为 true 值:

               o -Dmanagement.health.probes.enabled

               o -Dmanagement.endpoint.health.probes.add-additional-paths

    Spring Boot Actuator Probes convention执行以下操作:

    • 使用主服务器端口(即 JAVA_TOOL_OPTIONS 上的 server.port 值)来设置 liveness 和 readiness 探针。

    • 将以下属性和值添加到 JAVA_TOOL_OPTIONS 环境变量:

              o -Dmanagement.health.probes.enabled="true"

              o -Dmanagement.endpoint.health.probes.add-additional-paths="true"

    应用此约定时,探针的暴露方式如下:

    • Liveness probe: /livez

    • Readiness probe: /readyz

    应用约定后的 PodIntent 示例:

    1. apiVersion: conventions.apps.tanzu.vmware.com/v1alpha1
    2. kind: PodIntent
    3. metadata:
    4. annotations:
    5. kubectl.kubernetes.io/last-applied-configuration: |
    6. {"apiVersion":"conventions.apps.tanzu.vmware.com/v1alpha1","kind":"PodIntent","metadata":{"annotations":{},"name":"spring-sample","namespace":"default"},"spec":{"template":{"spec":{"containers":[{"image":"springio/petclinic","name":"workload"}]}}}}
    7. ...
    8. status:
    9. conditions:
    10. - lastTransitionTime: "..." # This status indicates that all worked as expected
    11. status: "True"
    12. type: ConventionsApplied
    13. - lastTransitionTime: "..."
    14. status: "True"
    15. type: Ready
    16. observedGeneration: 1
    17. template:
    18. metadata:
    19. annotations:
    20. boot.spring.io/actuator: http://:8080/actuator
    21. boot.spring.io/version: 2.6.0
    22. conventions.apps.tanzu.vmware.com/applied-conventions: |-
    23. spring-boot-convention/spring-boot
    24. spring-boot-convention/spring-boot-web
    25. spring-boot-convention/spring-boot-actuator
    26. labels:
    27. conventions.apps.tanzu.vmware.com/framework: spring-boot
    28. spec:
    29. containers:
    30. - env:
    31. - name: JAVA_TOOL_OPTIONS
    32. value: -Dmanagement.endpoint.health.probes.add-additional-paths="true" -Dmanagement.endpoints.web.base-path="/actuator" -Dmanagement.health.probes.enabled="true" -Dmanagement.server.port="8081" -Dserver.port="8080"
    33. image: index.docker.io/springio/petclinic@sha256:...
    34. name: workload
    35. livenessProbe:
    36. httpGet:
    37. path: /livez
    38. port: 8080
    39. scheme: HTTP
    40. ports:
    41. - containerPort: 8080
    42. protocol: TCP
    43. readinessProbe:
    44. httpGet:
    45. path: /readyz
    46. port: 8080
    47. scheme: HTTP
    48. resources: {}

    2.3Application Live View convention service

    Application Live View convention执行以下操作:

    • 在 PodTemplateSpec 中添加一个标签tanzu.app.live.view: "true"

    • 在 PodTemplateSpec 中添加一个标签tanzu.app.live.view.application.name: APP-NAME

    • 将以下属性和值添加到 JAVA_TOOL_OPTIONS 环境变量:

                 o -Dmanagement.endpoint.health.show-details=always

                 o -Dmanagement.endpoints.web.exposure.include=*

    应用约定后的 PodIntent 示例:

    1. status:
    2. conditions:
    3. - lastTransitionTime: "2021-10-26T11:26:35Z"
    4. status: "True"
    5. type: ConventionsApplied
    6. - lastTransitionTime: "2021-10-26T11:26:35Z"
    7. status: "True"
    8. type: Ready
    9. observedGeneration: 1
    10. template:
    11. metadata:
    12. annotations:
    13. conventions.apps.tanzu.vmware.com/applied-conventions: |-
    14. appliveview-sample/app-live-view-connector
    15. appliveview-sample/app-live-view-appflavours
    16. appliveview-sample/app-live-view-systemproperties
    17. labels:
    18. tanzu.app.live.view: "true"
    19. tanzu.app.live.view.application.flavours: spring-boot
    20. tanzu.app.live.view.application.name: petclinic
    21. spec:
    22. containers:
    23. - env:
    24. - name: JAVA_TOOL_OPTIONS
    25. value: -Dmanagement.endpoint.health.show-details=always -Dmanagement.endpoints.web.exposure.include=*
    26. image: index.docker.io/kdvolder/alv-spring-petclinic:latest@sha256:1aa7bd228137471ea38ce36cbf5ffcd629eabeb8ce047f5533b7b9176ff51f98
    27. name: workload
    28. resources: {}

    在注入约定后,应用可在TAP的Live View页面进行实时监控,如下所示 :

    2.4Service intent conventions

    Service intent conventions不会改变最终部署的行为,但您可以将它们用作附加信息以在供应链中进行处理。 例如,当应用程序需要绑定到数据库服务时,此约定为每个检测到的依赖项添加注释和标签到 PodTemplateSpec, 还向conventions.apps.tanzu.vmware.com/applied-conventions 添加注释和标签。

    当您应用 Pod Intent 并且镜像包含依赖项(例如 MySQL)时,约定的输出将是:

    1. apiVersion: conventions.apps.tanzu.vmware.com/v1alpha1
    2. kind: PodIntent
    3. metadata:
    4. annotations:
    5. kubectl.kubernetes.io/last-applied-configuration: |
    6. {"apiVersion":"conventions.apps.tanzu.vmware.com/v1alpha1","kind":"PodIntent","metadata":{"annotations":{},"name":"spring-sample","namespace":"default"},"spec":{"template":{"spec":{"containers":[{"image":"springio/petclinic","name":"workload"}]}}}}
    7. creationTimestamp: "..."
    8. generation: 1
    9. name: spring-sample
    10. namespace: default
    11. resourceVersion: "..."
    12. uid: ...
    13. spec:
    14. serviceAccountName: default
    15. template:
    16. metadata: {}
    17. spec:
    18. containers:
    19. - image: springio/petclinic
    20. name: workload
    21. resources: {}
    22. status:
    23. conditions:
    24. - lastTransitionTime: "..." # This status indicates that all worked as expected
    25. status: "True"
    26. type: ConventionsApplied
    27. - lastTransitionTime: "..."
    28. status: "True"
    29. type: Ready
    30. observedGeneration: 1
    31. template:
    32. metadata:
    33. annotations:
    34. boot.spring.io/actuator: http://:8080/actuator
    35. boot.spring.io/version: 2.3.3.RELEASE
    36. conventions.apps.tanzu.vmware.com/applied-conventions: |-
    37. spring-boot-convention/spring-boot
    38. spring-boot-convention/spring-boot-web
    39. spring-boot-convention/spring-boot-actuator
    40. spring-boot-convention/service-intent-mysql
    41. services.conventions.apps.tanzu.vmware.com/mysql: mysql-connector-java/8.0.21
    42. labels:
    43. conventions.apps.tanzu.vmware.com/framework: spring-boot
    44. services.conventions.apps.tanzu.vmware.com/mysql: workload
    45. spec:
    46. containers:
    47. - env:
    48. - name: JAVA_TOOL_OPTIONS
    49. value: Dmanagement.endpoints.web.base-path="/actuator" -Dmanagement.server.port="8081" -Dserver.port="8080"
    50. image: index.docker.io/springio/petclinic@sha256:...
    51. name: workload
    52. ports:
    53. - containerPort: 8080
    54. protocol: TCP
    55. resources: {}

    3.价值总结

    通过对TAP约定服务的实现机制及4类约定服务的详细介绍,相信您现在一定对其的能力有了进一步的了解,让我们在此对它能为开发测试及应用运维人员带来的核心价值进行深入的总结。

    Tanzu Application Platform通过供应链编排帮助开发人员及应用运维人员通过 URL 将其代码转换为容器化工作负载。约定服务是供应链编排工作机制中的关键组成部分,它使应用运维人员能够有效地运用他们的专业知识,在平台上创建工作负载时为其组织指定运行时最佳实践、策略和约定。 当组织的约定被一致地、大规模地应用并且不妨碍应用程序开发人员的开发效率时,这个组件的价值就变得显而易见了。

    我们会在后续的系列文章中进一步介绍 TAP 的其它组件,敬请关注与期待!

    如果您有任何反馈,也请联系我们!

    4.作者介绍

    肖林,VMware 现代化应用平台高级解决方案架构师,主要负责VMware Tanzu云原生技术解决方案的架构与设计;在此之前,在IBM任职负责大中华区云原生技术解决方案架构,主导了多个云原生解决方案的设计。

    个人从业16年, Cloud Native拥护者&Agile实践者, 在容器,大规模分布式服务及治理,应用现代化、Spring等领域都有技术积累,同时具备CNCF CKA、CNCF CKS、Spring Professional等认证。

    来源|公众号:VMwareTanzu云原生

  • 相关阅读:
    Teracloud+GoodSync
    有一个有序数字序列,从小到大排序,将一个新输入的数插入到序列中,保证插入新数后,序列仍然是升序
    react实现转盘抽奖功能
    【算法】模拟退火算法(SAA,Simulated Annealing Algorithm)
    深入解析Web通信 HTTP、HTTPS 和 WebSocket
    Python 操作 lxml库与Xpath(爬取网页指定内容)
    RabbitMQ的 AMQP协议都是些什么内容呢
    编码中的Adapter,不仅是一种设计模式,更是一种架构理念与解决方案
    “errcode“:40164,“errmsg“:“invalid ip ...微信公众号开发调用失败的解决办法
    unix环境编程:标准I/O库
  • 原文地址:https://blog.csdn.net/qq_42906753/article/details/125971761