GitLab Runner 的 K3S 部署问题:“服务器找不到请求的资源”

问题描述 投票:0回答:1

我在尝试从 GitLab Runner 在 K3S 集群上部署 Kubernetes 资源时遇到问题。该错误消息表明服务器找不到所请求的资源。相关详情如下:

  • GitLab CI/CD 配置为部署 Kubernetes 资源。
  • 该集群是K3S集群。
  • 使用kubectl apply命令,请求API server时出现错误。
  • 我可以使用 kubectl get po -n kube-system 成功从集群中检索信息。
  • GitLab Runner 具有必要的权限,因为它可以从集群中获取 pod。

这是我的 .gitlab-ci.yaml 文件的相关部分:


deploy:
  stage: deploy
  image:
    name: harbor.localdomain.ma/devops/lachlanevenson/k8s-kubectl:v1.9.2
    entrypoint: []
  extends:
    - .tag-small
  script:
    - mkdir $HOME/.kube
    - "echo $KUBECONF_DEFAULT | base64 -d > $HOME/.kube/config"
    - kubectl version --insecure-skip-tls-verify
    - kubectl get po -n kube-system 
    - pwd 
    - ls -lrth kubernetes
    - echo $CI_PROJECT_URL
    - cat /builds/BS-ocps/deployments/kubernetes/deployment.yaml > test.yaml
    - kubectl apply -f test.yaml -n bs -v=8 --insecure-skip-tls-verify
    - kubectl apply -f /builds/BS-ocps/deployments/kubernetes/service.yaml -n bs -v=8 --insecure-skip-tls-verify
    - kubectl get po -n bs

我得到的错误:

I1227 14:18:35.820599      57 loader.go:357] Config loaded from file /root/.kube/config
I1227 14:18:35.873465      57 round_trippers.go:414] GET https://CLUSTER_IP:6443/swagger-2.0.0.pb-v1
I1227 14:18:35.873550      57 round_trippers.go:421] Request Headers:
I1227 14:18:35.873567      57 round_trippers.go:424]     Accept: application/json, */*
I1227 14:18:35.873578      57 round_trippers.go:424]     User-Agent: kubectl/v1.9.2 (linux/amd64) kubernetes/5fa2db2
I1227 14:18:35.906258      57 round_trippers.go:439] Response Status: 404 Not Found in 32 milliseconds
I1227 14:18:35.906318      57 round_trippers.go:442] Response Headers:
I1227 14:18:35.906331      57 round_trippers.go:445]     X-Content-Type-Options: nosniff
I1227 14:18:35.906341      57 round_trippers.go:445]     X-Kubernetes-Pf-Flowschema-Uid: 3a3edf31-1f82-4b20-a18b-daed7dae0d7d
I1227 14:18:35.906393      57 round_trippers.go:445]     X-Kubernetes-Pf-Prioritylevel-Uid: a583e898-18a5-4e9d-9953-97a43f37688e
I1227 14:18:35.906403      57 round_trippers.go:445]     Content-Length: 19
I1227 14:18:35.906412      57 round_trippers.go:445]     Date: Wed, 27 Dec 2023 14:18:43 GMT
I1227 14:18:35.906422      57 round_trippers.go:445]     Audit-Id: 58cfcb04-f093-44b4-b3a5-b1c4d42f8816
I1227 14:18:35.906432      57 round_trippers.go:445]     Cache-Control: no-cache, private
I1227 14:18:35.906441      57 round_trippers.go:445]     Content-Type: text/plain; charset=utf-8
I1227 14:18:35.909213      57 request.go:873] Response Body: 404 page not found
I1227 14:18:35.912075      57 helpers.go:201] server response object: [{
  "metadata": {},
  "status": "Failure",
  "message": "the server could not find the requested resource",
  "reason": "NotFound",
  "details": {
    "causes": [
      {
        "reason": "UnexpectedServerResponse",
        "message": "404 page not found"
      }
    ]
  },
  "code": 404
}]
F1227 14:18:35.912159      57 helpers.go:119] Error from server (NotFound): the server could not find the requested resource
Cleaning up file based variables
00:00
ERROR: Job failed: command terminated with exit code 255

任何有关解决此问题的见解或建议将不胜感激。预先感谢!

我尝试从我的机器上在集群上运行deployment.yaml,它可以工作,所以没有任何问题。

kubernetes gitlab-ci pipeline kubectl k3s
1个回答
0
投票

我遇到此错误是因为我在运行程序中使用过时的 kubectl 映像,在更新到最新版本时一切正常。

© www.soinside.com 2019 - 2024. All rights reserved.