1

I am trying to create a deployment declaratively, using kubectl apply. The below configuration is created just fine when I do

kubectl create -f postgres-deployment.yaml

but if I go

kubectl apply -f postgres-deployment.yaml

I am presented with the lovely error message:

error: unable to decode "postgres-deployment.yaml": no kind "Deployment" is registered for version "apps/v1beta1"

I have tried searching for an explanation to what this means but I cannot figure it out.

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: postgres-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: postgres
  template:
    metadata:
      labels:
        app: postgres
    spec:
      containers:
      - name: postgres
        image: postgres:10.1
        ports:
        - containerPort: 5432
Mattias Petter Johansson
  • 1,064
  • 1
  • 15
  • 32
  • can you post the output for `kubectl version` – frankgreco Dec 20 '17 at 16:11
  • 2
    From `kubectl apply --help`: `To use 'apply', always create the resource initially with either 'apply' or 'create --save-config'`. So maybe try `kubectl create --save-config -f postgres-deployment.yaml` and then use `kubectl apply -f postgres-deployment.yaml`. – fishi0x01 Dec 20 '17 at 16:12
  • Does this answer your question? [kubectl apply vs kubectl create?](https://stackoverflow.com/questions/47369351/kubectl-apply-vs-kubectl-create) – Inanc Gumus Apr 21 '20 at 12:51

1 Answers1

2

Old Kubernetes versions supported the Deployment object on the extensions/v1beta1 API group. That is no longer the case.

For Kubernetes versions before 1.9.0 you should use the API group apps/v1beta2.

In Kubernetes 1.9 and above you should use the API group apps/v1.

Jose Armesto
  • 12,794
  • 8
  • 51
  • 56
  • But why does `kubectl create` work and `kubectl apply` doesn't? I would expect that both fail when a wrong API version is used. – fishi0x01 Dec 20 '17 at 17:06
  • I'm just assuming here, but since `kubectl apply`is part of the declarative way of creating objects, it performs actions than eventually ensures the api group of the object being created is not deprecated. On the other hand `kubectl create` is part of the imperative way of creating objects, and so, in this way of managing objects, the object just gets created if the api group exists, even though is deprecated. I'd bet kubectl create would fail if you replace `apps/v1beta1` with "bananas". – Jose Armesto Dec 20 '17 at 17:45
  • Client Version or Server version? – Lin Du May 30 '18 at 09:18