Kubernetes Jenkins Deployment API版本不匹配

时间:2018-08-29 08:31:49

标签: jenkins deployment kubernetes google-cloud-platform google-compute-engine

如果要从本地计算机上载以下部署文件,则它可以正常工作。

kind: Deployment
apiVersion: apps/v1
metadata:
  name: api
  namespace: app
spec:
  replicas: 2
  selector:
    matchLabels:
      run: api
  template:
    metadata:
      labels:
        run: api
    spec:
      containers:
      - name: api
        image: gcr.io/myproject/api:1535462260754
        ports:
        - containerPort: 8080
        readinessProbe:
          httpGet:
            path: /_ah/health
            port: 8080
          initialDelaySeconds: 10
          periodSeconds: 5

同一台运行Jenkins的远程Compute Engine计算机上。在这台机器上,使用ssh我也可以应用此配置。在Jenkins shell执行下,总是抛出

error: unable to recognize "./dist/cluster/api.deployment.yaml": no matches for kind "Deployment" in version "apps/v1"

我试图将apiVersion更改为apps/v1beta1,也更改为extensions/v1beta1。 不知道该怎么办。

更新1

Compute Engine上的Kubectl版本:

Client Version: version.Info{Major:"1", Minor:"11", GitVersion:"v1.11.2", GitCommit:"bb9ffb1654d4a729bb4cec18ff0 88eacc153c239", GitTreeState:"clean", BuildDate:"2018-08-07T23:17:28Z", GoVersion:"go1.10.3", Compiler:"gc", Pla tform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"9+", GitVersion:"v1.9.7-gke.5", GitCommit:"9b635efce81582e1da13b3 5a7aa539c0ccb32987", GitTreeState:"clean", BuildDate:"2018-08-02T23:42:40Z", GoVersion:"go1.9.3b4", Compiler:"gc ", Platform:"linux/amd64"}

更新2

在Jenkins内部运行此程序。

Client Version: version.Info{Major:"1", Minor:"11", GitVersion:"v1.11.2", GitCommit:"bb9ffb1654d4a729bb4cec18ff088eacc153c239", GitTreeState:"clean", BuildDate:"2018-08-07T23:17:28Z", GoVersion:"go1.10.3", Compiler:"gc", Platform:"linux/amd64"}
Error from server (Forbidden): <html><head><meta http-equiv='refresh' content='1;url=/securityRealm/commenceLogin?from=%2Fversion%3Ftimeout%3D32s'/><script>window.location.replace('/securityRealm/commenceLogin?from=%2Fversion%3Ftimeout%3D32s');</script></head><body style='background-color:white; color:white;'>


Authentication required
<!--
You are authenticated as: anonymous
Groups that you are in:

Permission you need to have (but didn't): hudson.model.Hudson.Read
... which is implied by: hudson.security.Permission.GenericRead
... which is implied by: hudson.model.Hudson.Administer
-->

</body></html>

2 个答案:

答案 0 :(得分:1)

您的Jenkins服务器或代理中的kubectl版本可能较旧。尝试从Jenkins作业运行kubectl version来检查不匹配情况。

答案 1 :(得分:1)

感谢 @csanchez ,我发现需要在jenkins用户下获取凭据。为此,我只运行了以下命令:

gcloud container clusters get-credentials cluster-1 --zone=my-cluster-zone --project myproject