All Products
Search
Document Center

Container Service for Kubernetes:Build a Q&A agent with Kagent on ACK

Last Updated:Dec 16, 2025

This guide demonstrates how to deploy a Question & Answer (Q&A) agent using Kagent. The agent leverages the qwen3-coder-plus model from Alibaba Cloud Model Studio and a fetch Model Context Protocol (MCP) service to retrieve and summarize web page content in real time.

Preparations

  1. Create a namespace named kagent in your ACK cluster.

  2. Install the kagent-crds and kagent applications in the kagent namespace from the ACK Marketplace or using Applications > Helm.

  3. Activate the Alibaba Cloud Model Studio and create an API key.

Step 1: Create a ModelConfig

  1. Get the KubeConfig of your cluster and use kubectl to connect to the cluster. If your cluster does not have public network access enabled, you can use Workbench to connect to the cluster over the internal network. On the Cluster Information page, click Manage Clusters Using Workbench in the upper-right corner.

  2. Export your Model Studio API key as an environment variable and create a Secret in the kagent namespace.

    export PROVIDER_API_KEY=${Your_Model_Studio_API_Key}
    kubectl create secret generic bailian-apikey -n kagent --from-literal credential="$PROVIDER_API_KEY"
  3. Apply the following YAML to create the ModelConfig resource. The provider is set to OpenAI because Model Studio exposes an OpenAI-compatible API.

    kubectl -n kagent apply -f - <<EOF
    apiVersion: kagent.dev/v1alpha2
    kind: ModelConfig
    metadata:
      name: bailian-provider-config
    spec:
      model: qwen3-coder-plus
      apiKeySecret: bailian-apikey
      apiKeySecretKey: credential
      openAI:
        baseUrl: https://dashscope-intl.aliyuncs.com/compatible-mode/v1
      provider: OpenAI
    EOF

Step 2: Deploy the fetch MCP server

  1. Deploy the fetch MCP server in your ACK cluster.

    kubectl -n kagent apply -f - <<EOF
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: streamablehttp-fetch-deployment
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: streamablehttp-fetch
      template:
        metadata:
          labels:
            app: streamablehttp-fetch
        spec:
          containers:
          - name: streamablehttp-fetch-container
            image: registry-cn-hangzhou.ack.aliyuncs.com/dev/streamablehttp-fetch:latest
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: streamablehttp-fetch-service
    spec:
      selector:
        app: streamablehttp-fetch
      ports:
        - protocol: TCP
          port: 3000
          targetPort: 3000
      type: ClusterIP
    EOF

Step 3: Register the MCP Server

  1. Create the RemoteMCPServer resource to register the fetch service with Kagent. This tells the system how to communicate with the MCP server deployed in the previous step.

    kubectl -n kagent apply -f - <<EOF
    apiVersion: kagent.dev/v1alpha2
    kind: RemoteMCPServer
    metadata:
      name: streamablehttp-fetch
    spec:
      description: A Model Context Protocol server that provides web content fetching capabilities. This server enables LLMs to retrieve and process content from web pages, converting HTML to Markdown for easier consumption.
      protocol: STREAMABLE_HTTP
      sseReadTimeout: 5m0s
      terminateOnClose: true
      timeout: 30s
      url: http://streamablehttp-fetch-service:3000/
    EOF
  2. Verify that the MCP server is successfully registered and accepted.

    kubectl get RemoteMCPServer -n kagent

    Expected output:

    NAME                   PROTOCOL          URL                                        ACCEPTED
    streamablehttp-fetch   STREAMABLE_HTTP   http://streamablehttp-fetch-service:3000/   True

Step 4: Create the agent

  1. Apply the Agent configuration.

    kubectl -n kagent apply -f - <<EOF
    apiVersion: kagent.dev/v1alpha2
    kind: Agent
    metadata:
      name: gateway-api-professor
      namespace: kagent
    spec:
      declarative:
        modelConfig: bailian-provider-config
        stream: true
        systemMessage: |-
          You are a friendly and helpful agent. Use the streamablehttp-fetch tool to get GatewayAPI information from the following URLs to answer user questions about GatewayAPI.
          
          # Links
          - intro: https://gateway-api.sigs.k8s.io/
          - api-overview: https://gateway-api.sigs.k8s.io/concepts/api-overview/
          - use-case: https://gateway-api.sigs.k8s.io/concepts/use-cases/
          - servicemesh: https://gateway-api.sigs.k8s.io/mesh/
          - implementations: https://gateway-api.sigs.k8s.io/implementations/
          - v1.4 support overview: https://gateway-api.sigs.k8s.io/implementations/v1.4/
          - Full spec, large page: https://gateway-api.sigs.k8s.io/reference/spec/
    
          # Instructions
    
          - If a user's question is unclear, ask for clarification before running any tools.
          - Be friendly and enthusiastic in your responses to the user.
          - If you do not know how to answer a question, do not make up an answer.
            Reply with "Sorry, I don't know how to answer that question" and ask the user to clarify.
          - If the user asks for a summary or an overview, make sure to read the entire text before answering.
    
          # Response format
          - Always reply in Markdown format.
          - Your response must include a summary of the actions you performed and an explanation of the results.
        tools:
        - type: McpServer
          mcpServer:
            apiGroup: kagent.dev
            kind: RemoteMCPServer
            name: streamablehttp-fetch
            toolNames:
            - fetch
      description: This agent primarily answers questions related to the GatewayAPI specification.
      type: Declarative
    EOF
  2. Verify that the agent and dependent components are running.

    kubectl get pod -n kagent

    Expected output:

    NAME                                              READY   STATUS    RESTARTS   AGE
    gateway-api-professor-7cb6496b9d-l7nlj            1/1     Running   0          3m1s
    kagent-controller-794fc765df-hqswt                1/1     Running   0          45m
    kagent-ui-569cb875c6-h55mg                        1/1     Running   0          45m
    streamablehttp-fetch-deployment-75d5cd86cf-h9rvp   1/1     Running   0          4m3s

Step 5: Access the agent

Kagent includes a built-in Web UI for interacting with the agent.

  1. Use port forwarding to expose the kagent-ui service to your local machine.

    kubectl port-forward -n kagent service/kagent-ui 8082:8080
  2. Open your browser and navigate to http://localhost:8082.

    1. Sample interaction 1: What are the APIs in the Gateway API?

      image

      image

    2. Sample interaction 2: Which implementation currently has the most comprehensive support for Gateway API features?

      image

      image