When I try to build a new image to Kubernetes, I got this error:
**unable to decode "K8sDeploy.yaml": no kind "Deployment" is registered for version "apps/v1"**
Thie error began when I updated the Kubernetes version, here my version info:
Client Version: v1.19.2
Server Version: v1.16.13
I tried also to build by my localhost and does work, but by Jenkins don't.
Somebody knows to solve this?
To check what apiVersion
supports a Deployment
resource in your kubernetes cluster you may run:
$ kubectl explain deployment | head -2
and you can be almost sure that the result will be as follows:
KIND: Deployment
VERSION: apps/v1
All modern kubernetes versions use apps/v1
, which was available since v1.9
, so for quite a long time already. As you may see here, older versions which were still available in kubernetes 1.15
have been deprecated in 1.16
.
Client Version: v1.19.2 Server Version: v1.16.13
As stated above, in kubernetes 1.16
, Deployment
must use apps/v1
and there is no possibility to use older api versions like extensions/v1beta1
, apps/v1beta1
or apps/v1beta2
which were still avilable in 1.15
.
Your issue seems to me rather an error from Jenkins (possibly old version of Jenkins itself or some of its plugins or perhaps something with its configuration) which is not able to recognize/parse the correct (and currently required) apiVersion
for Deployment
resource.
For troubleshooting purpose you can try and change the apiVersion
to one of the listed above. This should give you a different error (this time from kubernetes API server) as in 1.16
it won't be able to recognize it.
But at least it should give you a clue. If with older apiVersion
your Jenkins doesn't complain any more, it would mean that it is set to work with older API versions and an update may help.
I see you filed an issue on kubernetes GitHub so let's wait what they say, but as I said before to me it doesn't look like an issue with kubernetes but rather with Jenkins ability to parse a legitimate Deployment
yaml
.
I updated my Kubernetes version from 1.5 to 1.9, when i force the Kubectl command, does work, just by Jenkis doesn't, as you request follow my k8sdeploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: cbbox
labels:
app: cbbox
spec:
replicas: 1
selector:
matchLabels:
app: cbbox
template:
metadata:
labels:
app: cbbox
spec:
containers:
- image: myregistryrepository
name: cbbox
imagePullPolicy: Always
ports:
- containerPort: 8080
env:
- name: SECRET_DB_IP
valueFrom:
secretKeyRef:
name: cbboxsecret
key: SECRET_DB_IP
- name: SECRET_DB_PASSWORD
valueFrom:
secretKeyRef:
name: cbboxsecret
key: SECRET_DB_PASSWORD
- name: SECRET_DB_USER
valueFrom:
secretKeyRef:
name: cbboxsecret
key: SECRET_DB_USER
- name: SECRET_LDAP_DOMAIN
valueFrom:
secretKeyRef:
name: cbboxsecret
key: SECRET_LDAP_DOMAIN
- name: SECRET_LDAP_URLS
valueFrom:
secretKeyRef:
name: cbboxsecret
key: SECRET_LDAP_URLS
- name: SECRET_LDAP_BASE_DN
valueFrom:
secretKeyRef:
name: cbboxsecret
key: SECRET_LDAP_BASE_DN
- name: SECRET_TIME_ZONE
valueFrom:
secretKeyRef:
name: cbboxsecret
key: SECRET_TIME_ZONE
imagePullSecrets:
- name: acrcredentials
---
apiVersion: v1
kind: Service
metadata:
name: cbbox
spec:
type: LoadBalancer
ports:
- protocol: TCP
port: 80
targetPort: 8080
selector:
app: cbbox
Just check for case sensitivity in YAML file
In my case it was 'kind' field
kind: deployment
changed it to...
kind: Deployment