一键导入
plugin-kubernetes
Import and export Kubernetes YAML manifests with diagrams-js. Convert Kubernetes manifests to architecture diagrams and vice versa.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Import and export Kubernetes YAML manifests with diagrams-js. Convert Kubernetes manifests to architecture diagrams and vice versa.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Extend diagrams-js with custom import/export formats, metadata providers, and hooks. Create plugins for Docker Compose, Terraform, cloud provider metadata, and more.
Command-line interface for diagrams-js. Install @diagrams-js/cli and use diagrams <command> to render, export, diff, init, watch, and manage plugins. Cross-platform CLI with programmatic API. Supports file and stdin input.
Visual diff for diagrams. Compare two versions of a diagram to see added, removed, and modified elements with color-coded side-by-side rendering. Perfect for code reviews, documentation, and architecture evolution tracking.
Create custom plugins for diagrams-js to extend import/export capabilities. Package structure, plugin API, best practices, and real-world examples. Use context.lib for runtime exports, context.loadResourcesList for resource discovery, and context.loadYaml for YAML parsing without bundling dependencies.
Using diagrams-js in browsers with CDN (esm.sh), bundlers, and import maps. DOM insertion of SVG, data URLs for embedding in img tags, file downloads with diagram.save(). ESM-only - requires type="module".
Grouping nodes with diagram.cluster() and nested clusters via cluster.cluster(). Adding nodes to clusters with cluster.add(). Visual organization with themed backgrounds. Connecting nodes across clusters.
| name | plugin-kubernetes |
| description | Import and export Kubernetes YAML manifests with diagrams-js. Convert Kubernetes manifests to architecture diagrams and vice versa. |
| type | feature |
| library | diagrams-js |
Bidirectional conversion between Kubernetes YAML manifests and architecture diagrams.
npm install @diagrams-js/plugin-kubernetes
import { Diagram } from "diagrams-js";
import { kubernetesPlugin } from "@diagrams-js/plugin-kubernetes";
const diagram = Diagram("My K8s Application");
// Register the plugin
await diagram.registerPlugins([kubernetesPlugin]);
// Import from Kubernetes YAML
const k8sYaml = `
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-deployment
spec:
replicas: 3
selector:
matchLabels:
app: web
template:
spec:
containers:
- name: web
image: nginx:latest
ports:
- containerPort: 80
`;
await diagram.import(k8sYaml, "kubernetes");
// Render the diagram
const svg = await diagram.render();
import { Diagram, Node } from "diagrams-js";
import { kubernetesPlugin } from "@diagrams-js/plugin-kubernetes";
const diagram = Diagram("My K8s Application");
// Create nodes with Kubernetes metadata
const deployment = diagram.add(Node("web-deployment"));
deployment.metadata = {
kubernetes: {
kind: "Deployment",
namespace: "default",
spec: {
replicas: 3,
selector: { matchLabels: { app: "web" } },
template: {
spec: {
containers: [{ name: "web", image: "nginx:latest", ports: [{ containerPort: 80 }] }],
},
},
},
},
};
// Register plugin and export
await diagram.registerPlugins([kubernetesPlugin]);
const k8sYaml = await diagram.export("kubernetes");
Workloads:
Services & Networking:
Storage:
RBAC:
Cluster:
You can customize which icons are used for specific Kubernetes resources:
import { Diagram } from "diagrams-js";
import { createKubernetesPlugin } from "@diagrams-js/plugin-kubernetes";
const diagram = Diagram("My K8s Application");
// Create plugin with custom resource mappings
const plugin = createKubernetesPlugin({
defaultNamespace: "production",
imageMappings: {
// 1. Provider icon mapping - use built-in provider icons
"my-custom-deployment": {
provider: "onprem",
type: "compute",
resource: "Server",
},
"my-custom-service": {
provider: "onprem",
type: "database",
resource: "Postgresql",
},
// 2. Direct URL string - use a custom image URL
"my-frontend": "https://example.com/react-icon.png",
// 3. URL object - same as string but as object
"my-backend": {
url: "https://example.com/node-icon.svg",
},
// 4. Iconify icon - use icons from Iconify (https://iconify.design/)
// Format: { iconify: "prefix:name" }
"custom-app": {
iconify: "logos:kubernetes",
},
"redis-cache": {
iconify: "logos:redis",
},
},
});
await diagram.registerPlugins([plugin]);
The plugin supports Iconify icons, which provides access to 200,000+ open source icons:
{
iconify: "logos:kubernetes"; // Kubernetes logo
iconify: "logos:redis"; // Redis logo
iconify: "mdi:server"; // Material Design server icon
}
The plugin checks mappings by resource name first, then falls back to resource kind:
# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-api # Would normally show Deployment icon
// This mapping by RESOURCE NAME takes precedence
imageMappings: {
"my-api": { iconify: "logos:aws" } // Shows AWS icon instead of Deployment
}
// This mapping by KIND is the fallback
imageMappings: {
"Deployment": { iconify: "logos:kubernetes" } // Used if no "my-api" mapping
}
import { Diagram } from "diagrams-js";
import { kubernetesPlugin } from "@diagrams-js/plugin-kubernetes";
const diagram = Diagram("Production Architecture");
await diagram.registerPlugins([kubernetesPlugin]);
await diagram.import(k8sYaml, "kubernetes");
const svg = await diagram.render();
const diagram = Diagram("Environment Comparison");
await diagram.registerPlugins([kubernetesPlugin]);
await diagram.import([stagingManifest, productionManifest], "kubernetes");
const deployment = diagram.add(Node("api"));
deployment.metadata = {
kubernetes: {
kind: "Deployment",
namespace: "production",
spec: { replicas: 5, selector: { matchLabels: { app: "api" } } },
},
};
const k8sYaml = await diagram.export("kubernetes");
await diagram.import(existingK8sYaml, "kubernetes");
// ... modify diagram ...
const updatedYaml = await diagram.export("kubernetes");
kubernetesPluginPre-created instance:
import { kubernetesPlugin } from "@diagrams-js/plugin-kubernetes";
await diagram.registerPlugins([kubernetesPlugin]);
Provides importer (name: "kubernetes", .yml/.yaml) and exporter (name: "kubernetes", .yaml).
createKubernetesPlugin(config?)Factory for custom configuration:
import { createKubernetesPlugin, type ImageMappings } from "@diagrams-js/plugin-kubernetes";
const plugin = createKubernetesPlugin({
defaultNamespace: "production",
imageMappings: {
"custom-app": { iconify: "logos:kubernetes" },
"my-deployment": { provider: "k8s", type: "compute", resource: "Deploy" },
},
});
await diagram.registerPlugins([plugin]);
Config: defaultNamespace (default: "default"), imageMappings.
name: user-service not svc1kind, namespace, spec in node.metadata.kubernetes---await diagram.registerPlugins([kubernetesPlugin])node.metadata is Record<string, any>imageMappings with provider, URL, or IconifyapiVersion, kind, metadata.name are presentdiagrams-js-plugin-system skill