### Configure k8m Temporary Admin via Command-Line Arguments Source: https://github.com/weibaohui/k8m/blob/main/docs/temp-admin-config.md This section demonstrates how to configure the temporary administrator account for k8m using command-line arguments. It provides examples for both Linux/macOS and Windows, showing how to enable the feature, set the username, and specify the password. ```Bash # Linux/macOS ./k8m --enable-temp-admin --admin-username=admin --admin-password=your_secure_password # Windows k8m.exe --enable-temp-admin --admin-username=admin --admin-password=your_secure_password ``` -------------------------------- ### Install KinD for Kubernetes Cluster Source: https://github.com/weibaohui/k8m/blob/main/README.md Instructions for installing the KinD (Kubernetes in Docker) tool using Homebrew. KinD is used to create local Kubernetes clusters for testing and development. ```Shell brew install kind ``` -------------------------------- ### Configure SQLite Path (CLI) Source: https://github.com/weibaohui/k8m/blob/main/docs/database.md Configures the file path for the SQLite database using a command-line argument. ```shell --sqlite-path=./data/k8m.db ``` -------------------------------- ### Specify Database Driver (CLI) Source: https://github.com/weibaohui/k8m/blob/main/docs/database.md Sets the database driver using a command-line argument. Supported drivers include sqlite, mysql, and postgresql. ```shell --db-driver=sqlite # Or mysql, postgresql ``` -------------------------------- ### K8M Debugging Output Example Source: https://github.com/weibaohui/k8m/blob/main/README.md Illustrates the debugging output from K8M when run with increased verbosity, showing the status of ChatGPT integration, API keys, and model configurations. ```go ChatGPT 开启状态:true ChatGPT 启用 key:sk-hl**********************************************, url:https: // api.siliconflow.cn/v1 ChatGPT 使用环境变量中设置的模型:Qwen/Qwen2.5-7B-Instruc ``` -------------------------------- ### SQLite Backup using .backup command Source: https://github.com/weibaohui/k8m/blob/main/docs/database.md Safely backs up an SQLite database file, especially recommended when using WAL mode. ```shell sqlite3 ./data/k8m.db '.backup ./data/k8m.db.backup' ``` -------------------------------- ### Configure k8m Temporary Admin via Environment Variables (Windows CMD) Source: https://github.com/weibaohui/k8m/blob/main/docs/temp-admin-config.md This example shows how to configure k8m's temporary administrator account using environment variables in the Windows Command Prompt (CMD). It demonstrates setting the `ENABLE_TEMP_ADMIN`, `ADMIN_USERNAME`, and `ADMIN_PASSWORD` variables before running the k8m executable. ```CMD :: 启用临时管理员账户 set ENABLE_TEMP_ADMIN=true :: 设置管理员用户名 set ADMIN_USERNAME=admin :: 设置管理员密码 set ADMIN_PASSWORD=your_secure_password :: 启动应用 k8m.exe ``` -------------------------------- ### SQLite Backup using VACUUM INTO command Source: https://github.com/weibaohui/k8m/blob/main/docs/database.md Backs up an SQLite database file using the VACUUM INTO command, available in SQLite version 3.27.0 and above. ```shell sqlite3 ./data/k8m.db 'VACUUM INTO "./data/k8m.db.backup"' ``` -------------------------------- ### MCP Server Configuration JSON Source: https://github.com/weibaohui/k8m/blob/main/docs/mcp.md A JSON configuration example for integrating MCP tools like Trae, Cursor, and Claude Desktop. It specifies the URL for the k8m MCP server. ```json { "mcpServers": { "k8m": { "url": "http://localhost:3618/mcp/k8m/sse" } } } ``` -------------------------------- ### Configure k8m Temporary Admin via Environment Variables (Linux/macOS) Source: https://github.com/weibaohui/k8m/blob/main/docs/temp-admin-config.md This example illustrates how to set environment variables in Linux/macOS to configure k8m's temporary administrator account. It covers enabling the feature, setting the admin username, and defining the admin password before launching the application. ```Bash # 启用临时管理员账户 export ENABLE_TEMP_ADMIN=true # 设置管理员用户名 export ADMIN_USERNAME=admin # 设置管理员密码 export ADMIN_PASSWORD=your_secure_password # 启动应用 ./k8m ``` -------------------------------- ### Configure MCP Server in GitHub Copilot Source: https://github.com/weibaohui/k8m/blob/main/docs/mcp-github-copilot.md This snippet shows the JSON configuration for adding an MCP server to GitHub Copilot. It includes the server URL and authorization headers required for connection. ```json { "mcp": { "servers": { "k8s-mcp": { "url": "http://localhost:3618/mcp/k8m/sse", "headers": { "Authorization": "eyJhbGciOiJIUzI1..." } } } } } ``` -------------------------------- ### k8m Debugging Output for ChatGPT Source: https://github.com/weibaohui/k8m/blob/main/README_en.md Shows example output from k8m when run with increased verbosity (e.g., `./k8m -v 6`) to help debug ChatGPT integration. It confirms whether ChatGPT is enabled, displays masked API keys and URLs, and indicates the model being used. ```Go ChatGPT enabled status:true ChatGPT enabled key:sk-hl**********************************************, url:https://api.siliconflow.cn/v1 ChatGPT uses model set in environment variables:Qwen/Qwen2.5-Coder-7B-Instruc ``` -------------------------------- ### Configure SQLite DSN (CLI) Source: https://github.com/weibaohui/k8m/blob/main/docs/database.md Configures the SQLite database connection string (DSN) with advanced parameters using a command-line argument. This takes precedence over --sqlite-path. ```shell --sqlite-dsn="file:./data/k8m.db?_pragma=journal_mode(WAL)&_pragma=busy_timeout(5000)" ``` -------------------------------- ### Comprehensive HTTPRoute Configuration Source: https://github.com/weibaohui/k8m/blob/main/docs/gatewayapi.md An example of a complete HTTPRoute configuration combining path and header matching with weighted backend service distribution. ```YAML apiVersion: gateway.networking.k8s.io/v1beta1 kind: HTTPRoute spec: parentRefs: - name: example-gateway rules: - matches: - path: type: PathPrefix value: "/api" - headers: - name: "User-Agent" value: "mobile" backendRefs: - name: backend-v1 port: 8080 weight: 70 - name: backend-v2 port: 8081 weight: 30 ``` -------------------------------- ### Configure PostgreSQL Connection (Env Vars) Source: https://github.com/weibaohui/k8m/blob/main/docs/database.md Sets up connection parameters for a PostgreSQL database using environment variables, including host, port, user, password, database name, SSL mode, timezone, and log mode. ```env DB_DRIVER=postgresql PG_HOST=127.0.0.1 PG_PORT=5432 PG_USER=postgres PG_PASSWORD=yourpassword PG_DATABASE=k8m PG_SSLMODE=disable PG_TIMEZONE=Asia/Shanghai PG_LOGMODE=false ``` -------------------------------- ### Install k8m using kubectl Source: https://github.com/weibaohui/k8m/blob/main/README_en.md Provides the command to deploy k8m to a Kubernetes cluster using a raw YAML manifest from a GitHub repository. This is a common method for applying Kubernetes configurations. ```docker kubectl apply -f https://raw.githubusercontent.com/weibaohui/k8m/refs/heads/main/deploy/k8m.yaml ``` -------------------------------- ### Specify Database Driver (Env Var) Source: https://github.com/weibaohui/k8m/blob/main/docs/database.md Sets the database driver using an environment variable. Supported drivers include sqlite, mysql, and postgresql. ```env DB_DRIVER=sqlite # Or mysql, postgresql ``` -------------------------------- ### Configure SQLite Path (Env Var) Source: https://github.com/weibaohui/k8m/blob/main/docs/database.md Configures the file path for the SQLite database using an environment variable. ```env SQLITE_PATH=./data/k8m.db ``` -------------------------------- ### Configure MySQL Connection (Env Vars) Source: https://github.com/weibaohui/k8m/blob/main/docs/database.md Sets up connection parameters for a MySQL database using environment variables, including host, port, user, password, database name, character set, collation, and query parameters. ```env DB_DRIVER=mysql MYSQL_HOST=127.0.0.1 MYSQL_PORT=3306 MYSQL_USER=root MYSQL_PASSWORD=yourpassword MYSQL_DATABASE=k8m MYSQL_CHARSET=utf8mb4 MYSQL_COLLATION=utf8mb4_general_ci MYSQL_QUERY=parseTime=True&loc=Local MYSQL_LOGMODE=false ``` -------------------------------- ### Enable Frontend Hot Reloading Source: https://github.com/weibaohui/k8m/blob/main/README.md Starts the frontend development server using pnpm, enabling hot-reloading. The Vite service listens on port 3000 and forwards backend requests to port 3618. ```Bash cd ui pnpm run dev ``` -------------------------------- ### Configure SQLite DSN (Env Var) Source: https://github.com/weibaohui/k8m/blob/main/docs/database.md Configures the SQLite database connection string (DSN) with advanced parameters using an environment variable. This takes precedence over SQLITE_PATH. ```env SQLITE_DSN="file:./data/k8m.db?_pragma=journal_mode(WAL)&_pragma=busy_timeout(5000)" ``` -------------------------------- ### HTTPRoute Traffic Weighting Example Source: https://github.com/weibaohui/k8m/blob/main/docs/gatewayapi.md Configures an HTTPRoute to distribute traffic between multiple backend services based on specified weights. ```YAML apiVersion: gateway.networking.k8s.io/v1beta1 kind: HTTPRoute spec: parentRefs: - name: example-gateway rules: - matches: - path: type: PathPrefix value: "/api" backendRefs: - name: service-v1 port: 8080 weight: 70 - name: service-v2 port: 8081 weight: 30 ``` -------------------------------- ### k8m Docker Compose Configuration Source: https://github.com/weibaohui/k8m/blob/main/README_en.md Provides a Docker Compose configuration for running the k8m service. This setup includes defining the service, container name, image, restart policy, port mapping, environment variables (like timezone), and volume mounts for persistent data. ```YAML services: k8m: container_name: k8m image: registry.cn-hangzhou.aliyuncs.com/minik8m/k8m restart: always ports: - "3618:3618" environment: TZ: Asia/Shanghai volumes: - ./data:/app/data ``` -------------------------------- ### K8M Server Configuration Source: https://github.com/weibaohui/k8m/blob/main/docs/param-config.md Configures the K8M server, including the listening port for the web service, an option to print configuration on startup, and the product name. These settings can be managed via command-line arguments or environment variables. ```Go package main import ( "flag" "fmt" "os" ) func main() { // Server Configuration port := flag.Int("port", 3618, "Web service listening port") printConfig := flag.Bool("print-config", false, "Whether to print configuration on startup") productName := flag.String("product-name", "K8M", "Product name") flag.Parse() // Example usage if *printConfig { fmt.Printf("Product Name: %s\n", *productName) fmt.Printf("Web Server Port: %d\n", *port) } // Simulate server startup fmt.Printf("K8M server starting on port %d...\n", *port) // Environment variable overrides (example) if envPort := os.Getenv("PORT"); envPort != "" { fmt.Printf("Overriding port from environment variable: %s\n", envPort) } } ``` -------------------------------- ### Compile and Run k8m Backend Source: https://github.com/weibaohui/k8m/blob/main/README.md Commands to compile and run the k8m backend for local development. It includes fetching dependencies with `go mod tidy` and running the application using `air` for hot-reloading or directly with `go run`. ```Go #下载依赖 go mod tidy #运行 air #或者 go run main.go ``` -------------------------------- ### Configure k8m Temporary Admin via Environment Variables (Windows PowerShell) Source: https://github.com/weibaohui/k8m/blob/main/docs/temp-admin-config.md This example demonstrates how to configure k8m's temporary administrator account using environment variables in Windows PowerShell. It shows setting `ENABLE_TEMP_ADMIN`, `ADMIN_USERNAME`, and `ADMIN_PASSWORD` using the `$env:` scope before executing the k8m application. ```PowerShell # 启用临时管理员账户 $env:ENABLE_TEMP_ADMIN="true" # 设置管理员用户名 $env:ADMIN_USERNAME="admin" # 设置管理员密码 $env:ADMIN_PASSWORD="your_secure_password" # 启动应用 ./k8m.exe ``` -------------------------------- ### Build Frontend for k8m Source: https://github.com/weibaohui/k8m/blob/main/README.md Builds the frontend application for k8m. This step is necessary for local development as the backend embeds the frontend build artifacts. ```Bash cd ui pnpm run build ``` -------------------------------- ### K8M Database Configuration Source: https://github.com/weibaohui/k8m/blob/main/docs/param-config.md Specifies the database driver and configuration for K8M, supporting SQLite, MySQL, and PostgreSQL. For SQLite, it includes the path to the database file. These settings can be managed via command-line flags or environment variables. ```Go package main import ( "flag" "fmt" "os" ) func main() { // Database Configuration dbDriver := flag.String("db-driver", "sqlite", "Database driver: sqlite, mysql, postgresql") sqlitePath := flag.String("sqlite-path", "./data/k8m.db", "Path to the SQLite database file") flag.Parse() // Example usage fmt.Printf("Database driver: %s\n", *dbDriver) if *dbDriver == "sqlite" { fmt.Printf("SQLite database path: %s\n", *sqlitePath) } // Environment variable overrides (example) if envDBDriver := os.Getenv("DB_DRIVER"); envDBDriver != "" { fmt.Printf("Overriding database driver from environment variable: %s\n", envDBDriver) } } ``` -------------------------------- ### Create KinD Kubernetes Cluster Source: https://github.com/weibaohui/k8m/blob/main/README.md Command to create a new Kubernetes cluster named 'k8sgpt-demo' using the KinD tool. This sets up a local Kubernetes environment. ```Shell kind create cluster --name k8sgpt-demo ``` -------------------------------- ### Get Pod Linked PVC Source: https://github.com/weibaohui/k8m/blob/main/README_en.md Retrieves the PersistentVolumeClaim (PVC) linked to a specific Pod. This is useful for understanding storage dependencies of a Pod. ```bash get_pod_linked_pvc ``` -------------------------------- ### Run Dex OIDC Server (Shell) Source: https://github.com/weibaohui/k8m/blob/main/docs/oidc.md This command demonstrates how to run the Dex OIDC server using Docker. It maps the Dex port, mounts the `config.yaml` file, and specifies the Dex executable with the configuration file. ```Shell docker run -p 5556:5556 \ -v $(pwd)/config.yaml:/etc/dex/config.yaml \ dexidp/dex \ dex serve /etc/dex/config.yaml ``` -------------------------------- ### Get Pod Linked PV Source: https://github.com/weibaohui/k8m/blob/main/README_en.md Retrieves the PersistentVolume (PV) linked to a specific Pod. This helps in tracing the underlying storage provisioned for a Pod. ```bash get_pod_linked_pv ``` -------------------------------- ### Configure PostgreSQL Connection Parameters Source: https://github.com/weibaohui/k8m/blob/main/docs/param-config.md Details the configuration options for PostgreSQL connections, including host, port, user, password, database name, SSL mode, timezone, and log mode, which can be set via command-line arguments or environment variables. ```Shell PG_HOST=127.0.0.1 PG_PORT=5432 PG_USER=postgres PG_PASSWORD="" PG_DATABASE=k8m PG_SSLMODE=disable PG_TIMEZONE=Asia/Shanghai PG_LOGMODE=false ``` -------------------------------- ### Get Pod Environment Variables Source: https://github.com/weibaohui/k8m/blob/main/README_en.md Fetches the runtime environment variables of a Pod. This can be done either by executing the 'env' command within the Pod or by parsing the Pod's YAML definition. ```bash get_pod_linked_env ``` ```bash get_pod_linked_env_from_yaml ``` -------------------------------- ### 生成 Deployment 副本数一致性检测脚本 (Lua) Source: https://github.com/weibaohui/k8m/blob/main/docs/lua_inspection_script.md 一个完整的 Lua 脚本示例,用于检测所有 Deployment 资源的 spec.replicas 和 status.replicas 是否一致,并在不一致时调用 check_event。 ```Lua local deployments, err = kubectl:GVK("apps", "v1", "Deployment"):Cache(360):AllNamespace():List() if err then print("获取 Deployment 失败" .. tostring(err)) return end for _, deploy in ipairs(deployments) do local specReplicas = deploy.spec and deploy.spec.replicas or 1 local statusReplicas = deploy.status and deploy.status.replicas or 0 if specReplicas ~= statusReplicas then check_event("失败", "副本数不一致", {name=deploy.metadata.name, namespace=deploy.metadata.namespace}) end end print("Deployment 副本数一致性检测完成") ``` -------------------------------- ### Multi-Cluster Kubernetes Resource Operations Source: https://github.com/weibaohui/k8m/blob/main/README_en.md Enables performing common operations on Kubernetes resources across multiple clusters. This includes listing, getting, deleting, and describing resources, as well as retrieving Pod logs. ```bash list_k8s_resource ``` ```bash get_k8s_resource ``` ```bash delete_k8s_resource ``` ```bash describe_k8s_resource ``` ```bash get_pod_logs ``` -------------------------------- ### Apply KUBECONFIG via Command Line Source: https://github.com/weibaohui/k8m/blob/main/docs/param-config.md Demonstrates how to specify the KUBECONFIG file path using a command-line argument when running the k8m application. ```Shell ./k8m --port 8080 --kubeconfig /root/.kube/config ``` -------------------------------- ### Get Pod Resource Usage Source: https://github.com/weibaohui/k8m/blob/main/README_en.md Retrieves the resource usage details for a Pod, including CPU and memory requests, limits, allocatable values, and usage ratios. This is crucial for performance monitoring and capacity planning. ```bash get_pod_resource_usage ``` -------------------------------- ### Configure MCP Server for AI Tool Integration Source: https://github.com/weibaohui/k8m/blob/main/README_en.md Shows a JSON configuration for setting up an MCP Server, specifically for integrating with AI tools like Cursor, Claude Desktop, and Windsurf. It defines the server type and URL for SSE communication. ```json { "mcpServers": { "kom": { "type": "sse", "url": "http://IP:9096/sse" } } } ``` -------------------------------- ### Configure Dex OIDC Server (YAML) Source: https://github.com/weibaohui/k8m/blob/main/docs/oidc.md This snippet shows the `config.yaml` file used to configure the Dex OIDC server. It includes settings for the issuer, storage, web interface, static clients, and connectors like GitHub OAuth. ```YAML issuer: http://localhost:5556 storage: type: memory web: http: 0.0.0.0:5556 staticClients: - id: example-app redirectURIs: - "http://localhost:3000/auth/oidc/dex-github/callback" #请注意修改为真实的IP、端口 name: "Example App" secret: example-app-secret connectors: - type: github id: github name: GitHub config: clientID: XXXXXX #github oauth app id clientSecret: XXXXXXX #github oauth app secret redirectURI: http://localhost:5556/callback ``` -------------------------------- ### Manage Kubernetes Resources Source: https://github.com/weibaohui/k8m/blob/main/README_en.md Enables interaction with Kubernetes resources, including getting, describing, deleting, listing, patching (with JSON Patch), adding/deleting labels, and adding/deleting annotations. These operations are crucial for Dynamic Resource Management. ```bash get_k8s_resource ``` ```bash describe_k8s_resource ``` ```bash delete_k8s_resource ``` ```bash list_k8s_resource ``` ```bash list_k8s_event ``` ```bash patch_k8s_resource ``` ```bash label_k8s_resource ``` ```bash annotate_k8s_resource ``` -------------------------------- ### K8M CLI Usage Source: https://github.com/weibaohui/k8m/blob/main/README.md Demonstrates the command-line interface usage for the K8M tool, including options for enabling temporary admin accounts, setting passwords, debugging, and specifying kubeconfig paths. ```shell Usage of ./k8m: --enable-temp-admin 是否启用临时管理员账户配置,默认关闭 --admin-password string 管理员密码,启用临时管理员账户配置后生效 --admin-username string 管理员用户名,启用临时管理员账户配置后生效 --print-config 是否打印配置信息 (default false) --connect-cluster 启动集群是是否自动连接现有集群,默认关闭 -d, --debug 调试模式 --in-cluster 是否自动注册纳管宿主集群,默认启用 --jwt-token-secret string 登录后生成JWT token 使用的Secret (default "your-secret-key") -c, --kubeconfig string kubeconfig文件路径 (default "/root/.kube/config") --kubectl-shell-image string Kubectl Shell 镜像。默认为 bitnami/kubectl:latest,必须包含kubectl命令 (default "bitnami/kubectl:latest") --log-v int klog的日志级别klog.V(2) (default 2) --login-type string 登录方式,password, oauth, token等,default is password (default "password") --image-pull-timeout Node Shell、Kubectl Shell 镜像拉取超时时间。默认为 30 秒 --node-shell-image string NodeShell 镜像。 默认为 alpine:latest,必须包含`nsenter`命令 (default "alpine:latest") -p, --port int 监听端口 (default 3618) -v, --v Level klog的日志级别 (default 2) ``` -------------------------------- ### Set Environment Variables for ChatGPT Source: https://github.com/weibaohui/k8m/blob/main/README_en.md Demonstrates how to set environment variables to configure ChatGPT integration within the k8m project. This includes setting the OpenAI API key, API URL, and the desired model name. ```Bash export OPENAI_API_KEY="sk-XXXXX" export OPENAI_API_URL="https://api.siliconflow.cn/v1" export OPENAI_MODEL="Qwen/Qwen2.5-7B-Instruct" ``` -------------------------------- ### K8M Menu JSON Configuration Example Source: https://github.com/weibaohui/k8m/blob/main/docs/custom-menu.md This JSON structure defines a custom menu for K8M, including menu items, their properties like title, icon, event type, URL, order, and display conditions. It supports nested menus and custom JavaScript expressions for conditional display. ```json [ { "key": "menu_1640000000000_abc123", "title": "集群管理", "icon": "fa-server", "eventType": "url", "url": "/#/cluster/list", "order": 1, "show": "true", "children": [ { "key": "menu_1640000000001_def456", "title": "节点管理", "icon": "fa-desktop", "eventType": "url", "url": "/#/cluster/nodes", "order": 1, "show": "isPlatformAdmin()==true" } ] }, { "key": "menu_1640000000002_ghi789", "title": "应用部署", "icon": "fa-cube", "eventType": "custom", "customEvent": "window.location.href='/#/apps'", "order": 2, "show": "contains('admin', user.role)" } ] ``` -------------------------------- ### Create MCP Access Link Source: https://github.com/weibaohui/k8m/blob/main/docs/mcp.md This snippet shows the format of an MCP access link generated from the k8m platform. Users need to replace 'localhost' with the actual MCP Server IP address. ```bash http://localhost:3618/mcp/k8m/sse ``` -------------------------------- ### Configure k8m Temporary Admin via Kubernetes Deployment YAML Source: https://github.com/weibaohui/k8m/blob/main/docs/temp-admin-config.md This snippet shows how to enable and configure a temporary administrator account for k8m within a Kubernetes Deployment YAML file by setting specific environment variables. It includes enabling the feature, setting the username, and referencing a Kubernetes secret for the password. ```YAML apiVersion: apps/v1 kind: Deployment metadata: name: k8m spec: template: spec: containers: - name: k8m env: - name: ENABLE_TEMP_ADMIN value: "true" - name: ADMIN_USERNAME value: "admin" - name: ADMIN_PASSWORD valueFrom: secretKeyRef: name: k8m-admin-secret key: password ``` -------------------------------- ### 获取 Kubernetes 资源字段文档 (Lua) Source: https://github.com/weibaohui/k8m/blob/main/docs/lua_inspection_script.md 使用 lua_kubectl 的 Doc 方法获取 Kubernetes 资源的特定字段的文档说明,支持缓存以优化性能。 ```Lua -- 获取指定 Deployment 的副本数文档 local doc, err = kubectl:GVK("apps", "v1", "Deployment"):Cache(10):Doc("spec.replicas") if err then print( "获取 Deployment Doc 失败".. tostring(err)) return end print("Deployment Doc 获取成功: " .. doc) ``` -------------------------------- ### Manage Kubernetes Pods Source: https://github.com/weibaohui/k8m/blob/main/README_en.md Offers functionalities for interacting with Kubernetes Pods, including listing files within pods, deleting pod files, uploading files to pods (with text content support), retrieving pod logs, executing commands within pods, and getting linked services, ingresses, and endpoints. These are key Pod Management operations. ```bash list_pod_files ``` ```bash list_all_pod_files ``` ```bash delete_pod_file ``` ```bash upload_file_to_pod ``` ```bash get_pod_logs ``` ```bash run_command_in_pod ``` ```bash get_pod_linked_service ``` ```bash get_pod_linked_ingress ``` ```bash get_pod_linked_endpoints ``` -------------------------------- ### 检查 ConfigMap 数据是否为空 (Lua) Source: https://github.com/weibaohui/k8m/blob/main/docs/lua_inspection_script.md 遍历所有命名空间下的 ConfigMap,检查其 data 和 binaryData 字段是否为空,并在为空时上报事件。 ```Lua -- 检查所有命名空间下 data 和 binaryData 都为空的 ConfigMap local configmaps, err = kubectl:GVK("", "v1", "ConfigMap"):AllNamespace():List() if err then print("获取 ConfigMap 失败" .. tostring(err)) return end for _, cm in ipairs(configmaps) do local cmName = cm.metadata.name local cmNamespace = cm.metadata.namespace local isEmpty = true if cm.data then for k, v in pairs(cm.data) do isEmpty = false break end end if isEmpty and cm.binaryData then for k, v in pairs(cm.binaryData) do isEmpty = false break end end if isEmpty then check_event("失败", "[空数据] ConfigMap " .. cmNamespace .. "/" .. cmName .. " 的 data 和 binaryData 字段都为空", {namespace=cmNamespace, name=cmName}) end end print("ConfigMap 空数据检测完成") ``` -------------------------------- ### Configure MySQL Connection Parameters Source: https://github.com/weibaohui/k8m/blob/main/docs/param-config.md Specifies how to configure MySQL connection parameters using command-line arguments, environment variables, or default values. This includes host, port, user, password, database name, character set, collation, and extra parameters. ```Shell MYSQL_HOST=127.0.0.1 MYSQL_PORT=3306 MYSQL_USER=root MYSQL_PASSWORD="" MYSQ_DATABASE=k8m MYSQ_CHARSET=utf8mb4 MYSQ_COLLATION=utf8mb4_general_ci MYSQ_QUERY="parseTime=True&loc=Local" MYSQ_LOGMODE=false ``` -------------------------------- ### K8M AI Integration Configuration Source: https://github.com/weibaohui/k8m/blob/main/docs/param-config.md Manages AI integration settings for K8M, including enabling/disabling AI features, using built-in models, and configuring API keys, URLs, and model names for language models. These parameters can be set via command-line flags or environment variables. ```Go package main import ( "flag" "fmt" "os" ) func main() { // AI Integration Configuration enableAI := flag.Bool("enable-ai", true, "Enable or disable AI functionality") useBuiltinModel := flag.Bool("use-builtin-model", true, "Use built-in model or custom configuration") chatgptKey := flag.String("chatgpt-key", "", "API key for the language model") chatgptURL := flag.String("chatgpt-url", "", "Language model API endpoint address") chatgptModel := flag.String("chatgpt-model", "Qwen/Qwen2.5-7B-Instruct", "Name of the model to use") anySelect := flag.Bool("any-select", true, "Enable text arbitrary selection feature") flag.Parse() // Example usage if *enableAI { fmt.Println("AI functionality is enabled.") if *useBuiltinModel { fmt.Println("Using built-in model.") } if *chatgptKey != "" { fmt.Println("ChatGPT Key is provided.") } fmt.Printf("Using model: %s\n", *chatgptModel) if *anySelect { fmt.Println("Arbitrary text selection is enabled.") } } // Environment variable overrides (example) if envAPIKey := os.Getenv("OPENAI_API_KEY"); envAPIKey != "" { fmt.Printf("Overriding ChatGPT Key from environment variable.") } } ``` -------------------------------- ### K8M Authentication Configuration Source: https://github.com/weibaohui/k8m/blob/main/docs/param-config.md Configures authentication methods for K8M, supporting password, OAuth, and Token-based login. It includes settings for JWT secret key and temporary administrator credentials. These can be managed via command-line flags or environment variables. ```Go package main import ( "flag" "fmt" "os" ) func main() { // Authentication Configuration loginType := flag.String("login-type", "password", "Login method: password, OAuth, Token") jwtTokenSecret := flag.String("jwt-token-secret", "your-secret-key", "JWT signing secret key") enableTempAdmin := flag.Bool("enable-temp-admin", false, "Enable temporary administrator account") adminUsername := flag.String("admin-username", "", "Temporary administrator username") adminPassword := flag.String("admin-password", "", "Temporary administrator password") flag.Parse() // Example usage fmt.Printf("Login type configured: %s\n", *loginType) if *enableTempAdmin { fmt.Printf("Temporary admin enabled: Username=%s, Password=%s\n", *adminUsername, *adminPassword) } // Environment variable overrides (example) if envJWTSecret := os.Getenv("JWT_TOKEN_SECRET"); envJWTSecret != "" { fmt.Println("Overriding JWT secret from environment variable.") } } ```