通过 Kubernetes rest 打补丁 API

Patch through Kuberentes rest API

我正在尝试通过 kubernetes 设置最小副本来修补水平 Pod 自动缩放器 api

这是我正在使用的 curl

curl -k  \
    --request PATCH \
            --header "Authorization: Bearer $KUBE_TOKEN" \
            --header "Content-Type: application/strategic-merge-patch+json" \
            --data '{
                "apiVersion": "autoscaling/v1",
                "kind": "HorizontalPodAutoscaler",
                "metadata": {
                    "labels": {
                        "app.kubernetes.io/instance": "test"
                    },
                    "name": "test",
                    "namespace": "default"
                },
                "spec": {
                    "maxReplicas": 2,
                    "minReplicas": 1,
                    "scaleTargetRef": {
                        "apiVersion": "apps/v1",
                        "kind": "Deployment",
                        "name": "test"
                    },
                    "targetCPUUtilizationPercentage": 60
                }
            
            }' \
            https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_PORT_443_TCP_PORT/apis/autoscaling/v1/namespaces/default/horizontalpodautoscalers

我收到以下回复

{
  "kind": "Status",
  "apiVersion": "v1",
  "metadata": {
    
  },
  "status": "Failure",
  "message": "the server does not allow this method on the requested resource",
  "reason": "MethodNotAllowed",
  "details": {
    
  },
  "code": 405
}

谁能知道我哪里漏了?

谢谢

URL 路径必须包含名称:

/apis/autoscaling/v1/namespaces/{namespace}/horizontalpodautoscalers/{name}

它记录在这个页面上 https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#horizontalpodautoscaler-v1-autoscaling