Kubernetes jenkins deployment api version no matches

8/29/2018

The following deployment file is working if I'm uploading it from my local machine.

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

The same one is on remote Compute Engine machine which running Jenkins. On this machine, with ssh I'm also able to apply this config. Under the Jenkins shell execute it's always throws

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

I tried to change apiVersion to apps/v1beta1 and to extensions/v1beta1 as well. Don't know what to try else.

Update 1

kubectl version on Compute Engine:

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"}

Update 2

Run inside Jenkins job shown this.

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>
-- QuestionAndAnswer
deployment
google-cloud-platform
google-compute-engine
jenkins
kubernetes

2 Answers

8/29/2018

Probably the kubectl version in your Jenkins server or agent is old. Try running kubectl version from the Jenkins job to check for mismatches.

-- csanchez
Source: StackOverflow

8/29/2018

Thanks to @csanchez I figured out that I was needed to get credentials under jenkins user. For that I just ran this command:

gcloud container clusters get-credentials cluster-1 --zone=my-cluster-zone --project myproject
-- QuestionAndAnswer
Source: StackOverflow