开发 k8s 管理平台 - k8sailor 11. 展示 deployment 详情页

本文涉及的产品
容器服务 Serverless 版 ACK Serverless,952元额度 多规格
容器服务 Serverless 版 ACK Serverless,317元额度 多规格
简介: 开发 k8s 管理平台 - k8sailor 11. 展示 deployment 详情页

开发 k8s 管理平台 - k8sailor 11. 展示 deployment 详情页

原文地址: https://tangx.in/posts/books/k8sailor/chapter02/11-display-deployment-detail/
tag: https://github.com/tangx/k8sailor/tree/feat/11-display-deployment-detail

deployment-detail.png

之前在后端已经将详情页的展示接口拆成了 2个

  • 其一是根据 name 获取 单个 deployment /deployments/:name
  • 其二是根据 deployment name 获取 关联 的 pods 信息 /deployments/:name/pod

页面展示就是两个接口请求与数据展示的简单操作, 和之前 deployment 页面一样, 没什么好说的。

typescript 的 interface 衍生

不过, 在遇到第二个、第三个接口出现的时候, 发现之前对于 deployment list 返回的数据结构设计出现了问题。

当时是将 code, error 两个字段直接内嵌到 Deployment 的接口设计之中。

export interface Deployment {
    code: number
    error: string
    data: DeploymentItem[] 
}

export interface DeploymentItem {
    images: string[]
    name: string
    namespace: string
    replicas: number
    status: {
        availableReplicas: number
        replicas: number
        unavailableReplicas: number
    }
}

现在发现, 如果需要在对 单 Deployment多 Pod 进行返回的时候, 再重复这样将 code, error 耦合到响应接口里面就额外的冗余了。

因此, 在 /webapp/src/apis/httpc.ts 中单独抽象了一个 根响应接口 HttpcResponse, 包含了 code 和 error 字段。

// HttpcResponse 是 Server 端的基础响应结构体
// 具体的接口响应结果, 需要接口自行实现 HttpcReponse 的继承与 data 字段的覆盖
export interface HttpcResponse {
    code: number
    error: string
    data: Object
}

之后具体的接口响应接口, 都从 HttpcResponse 中衍生, 其行为只需要覆盖 data 字段即可。

// Deployment 定义 Deployment 数据字段
export interface Deployment {
    images: string[]
    name: string
    namespace: string
    replicas: number
    status: {
        availableReplicas: number
        replicas: number
        unavailableReplicas: number
    }
}


// DeploymentListResponse 继承并覆盖 data, 返回 deployment 的列表
export interface DeploymentListResponse extends HttpcResponse {
    data: Deployment[]
}

// DeploymentResponse 继承并覆盖 data, 返回 deployment 的单个字段
export interface DeploymentResponse extends HttpcResponse {
    data: Deployment
}

vue3 获取路由信息

https://next.router.vuejs.org/zh/api/#currentroute

vue3 setup 语法中, 倒入 vue-router 模块, 使用 useRouter() 方法获取到 router API。

就可以很方便的通过 router.currentRouter 获取到相关路由信息了。

// 路由表
const routes = [
    {
        path: "/deployments/:name",
        name: "DeploymentDetail",
        component: () => import('@/components/views/DeploymentDetail.vue')
    }
]

之前在路由表中定义路由信息的时候, 使用了 /deployments/:name 路径参数, 也是在这里的路由中获取。


import { useRouter } from "vue-router";

const router = useRouter()

// 获取 url 中的变量信息
const fetchUrlParams = function () {
  // 获取全路径
  // console.log("fullpath::::",router.currentRoute.value.fullPath);

  // 获取 query 参数
  // console.log("query::::",router.currentRoute.value.query);

  // 获取 路径参数
  // console.log("params::::",router.currentRoute.value.params);

  req.Params.name = router.currentRoute.value.params.name as string
  req.Params.namespace = router.currentRoute.value.query.namespace as string

}
相关实践学习
通过Ingress进行灰度发布
本场景您将运行一个简单的应用,部署一个新的应用用于新的发布,并通过Ingress能力实现灰度发布。
容器应用与集群管理
欢迎来到《容器应用与集群管理》课程,本课程是“云原生容器Clouder认证“系列中的第二阶段。课程将向您介绍与容器集群相关的概念和技术,这些概念和技术可以帮助您了解阿里云容器服务ACK/ACK Serverless的使用。同时,本课程也会向您介绍可以采取的工具、方法和可操作步骤,以帮助您了解如何基于容器服务ACK Serverless构建和管理企业级应用。 学习完本课程后,您将能够: 掌握容器集群、容器编排的基本概念 掌握Kubernetes的基础概念及核心思想 掌握阿里云容器服务ACK/ACK Serverless概念及使用方法 基于容器服务ACK Serverless搭建和管理企业级网站应用
相关文章
|
6天前
|
弹性计算 运维 Kubernetes
Kubernetes(K8S) Controller - Deployment 介绍
Kubernetes(K8S) Controller - Deployment 介绍
8 1
|
10天前
|
Kubernetes 网络协议 Python
运维开发.Kubernetes探针与应用
运维开发.Kubernetes探针与应用
32 2
|
24天前
|
存储 Kubernetes 容器
k8s卷管理-2
k8s卷管理-2
16 2
|
24天前
|
存储 Kubernetes 调度
k8s卷管理-1
k8s卷管理-1
13 2
|
6天前
|
Kubernetes Java Shell
Kubernetes(K8S) Deployment 升级和回滚
Kubernetes(K8S) Deployment 升级和回滚
5 0
|
6天前
|
Kubernetes Java Docker
Kubernetes(K8S) Deployment 拉取阿里云镜像部署
Kubernetes(K8S) Deployment 拉取阿里云镜像部署
16 0
|
1月前
|
Kubernetes 持续交付 Python
Kubernetes(通常简称为K8s)是一个开源的容器编排系统,用于自动化部署、扩展和管理容器化应用程序。
Kubernetes(通常简称为K8s)是一个开源的容器编排系统,用于自动化部署、扩展和管理容器化应用程序。
|
1月前
|
人工智能 运维 Cloud Native
|
13天前
|
监控 Kubernetes 开发者
不容忽视的实力!Rancher:容器编排平台的领军者,引领行业风潮无人不知无人不晓!
【8月更文挑战第6天】Rancher是容器编排领域的领航者,提供开源容器管理平台,简化Kubernetes操作,支持多集群管理及DevOps工具集成。其直观界面便于部署、监控容器化应用,并提供应用商店加速部署流程。Rancher具备高度灵活性与安全性,支持自动化备份、恢复及容器迁移,确保业务连续性。通过持续创新与社区合作,Rancher引领行业发展,赋能开发者实现高效软件交付。
30 0
|
19天前
|
Kubernetes Cloud Native 搜索推荐
探索云原生技术:Kubernetes在现代应用部署中的角色打造个性化移动体验:从开发到操作系统定制
【7月更文挑战第31天】本文深入探讨了云原生技术的核心组件之一——Kubernetes,并分析了其在现代云计算环境中的关键作用。通过实际代码示例和案例分析,文章揭示了Kubernetes如何优化资源管理、提高部署灵活性以及增强服务的可靠性。读者将获得对Kubernetes操作实践的直观理解,并认识到采用云原生架构对企业数字化转型的推动力。
34 0