You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure DevOps发布管道kubectl apply失败:请求资源未找到

Alright, let's break down your questions clearly:

1. Why you're seeing the "server could not find the requested resource" error

The #1 reason for this error is you haven't created an Azure Kubernetes Service (AKS) cluster yet.

Think about it: when you run kubectl apply, the command needs to communicate with a Kubernetes API server that lives inside a cluster. If there's no cluster, there's no API server to receive your request—so kubectl can't find any "resource" to act on, hence the error. Your build artifact (the Tomcat.yaml in the drop folder) being correct doesn't matter here; there's simply no target cluster to deploy to.

That said, just to cover all bases, if you did have a cluster, other possible issues could include:

  • Your Azure DevOps pipeline not being authenticated to access the cluster (via a service principal or managed identity)
  • Your Tomcat.yaml referencing custom resources that don't exist in a default cluster (like CRDs)
    But again, these are irrelevant right now because you don't have a cluster to begin with.
2. Can you replace LoadBalancer with NodePort in Azure DevOps?

Absolutely—this is a completely feasible approach, and it's a common choice for testing or environments where you don't want to pay for a public LoadBalancer IP. Here's what you need to know:

Key Differences Between the Two

  • LoadBalancer: Provisions a dedicated public IP from Azure (with associated costs) to expose your service directly to the internet.
  • NodePort: Exposes your service on a static port (between 30000-32767) across every node in your cluster. You access it using a node's public IP plus that static port.

How to Make the Switch

  1. Update your Tomcat.yaml: Find the Service section and change type: LoadBalancer to type: NodePort. You can optionally set a specific nodePort value (within the 30000-32767 range) if you want a fixed port; otherwise, Kubernetes will assign one automatically. Example snippet:
    apiVersion: v1
    kind: Service
    metadata:
      name: tomcat-service
    spec:
      type: NodePort
      ports:
        - port: 8080
          targetPort: 8080
          nodePort: 30001 # Optional fixed port
      selector:
        app: tomcat
    
  2. Update your Azure DevOps pipeline: Since you've already confirmed the build artifact is in the drop folder, you don't need to change the path to your Tomcat.yaml—just ensure the kubectl apply step uses the updated file (which will be part of your build output once you commit the yaml change).
  3. Access the service after deployment:
    • Get the public IP of any node in your AKS cluster (you can find this in the Azure portal under your cluster's "Nodes" tab, or run kubectl get nodes -o wide in a terminal with cluster access).
    • Navigate to http://<node-public-ip>:<nodePort> to reach your Tomcat instance.

Things to Keep in Mind

  • NodePort is great for testing, but not ideal for production: if nodes are replaced (e.g., during scaling or updates), their public IPs might change, breaking access.
  • If your cluster uses private nodes (no public IPs), you'll need an ingress controller or jumpbox to access the NodePort service from outside the cluster.

内容的提问来源于stack exchange,提问作者Swetha Swaminathan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 07:53:28