7
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

kubectlで no matches for kind "Deployment" in version "v1"

Posted at

概要

Deploymentするときに以下のエラーが。

$ kubectl create -f deploytest.yaml --record
error: unable to recognize "deploytest.yaml": no matches for kind "Deployment" in version "v1"

ちなみにyamlファイルは以下。

deploytest.yaml
apiVersion: v1
kind: Deployment
metadata:
  name: deploy-test
  namespace: test
spec:
  replicas: 2
  template:
    metadata:
      labels: 
        app: pod-example
    spec:
      containers:
      - name: nginx
        image: nginx:1.10
        ports:
        - containerPort: 80

調査

よく分からず記述していたが、エラーによるとどうやらapiVersionがよくなさそう。

この記事によると、KubernetesのリソースAPIは、そのAPIがどのAPIGROUPに属しているかで apiVersion の書き方が異なる、とのこと。

早速DeploymentがどのAPI groupに対応しているか調査する。

$ kubectl api-resources 
NAME                              SHORTNAMES         APIGROUP                       NAMESPACED   KIND
・
・
deployments                       deploy             apps                           true         Deployment
・
・
deployments                       deploy             extensions                     true         Deployment
・
・

Deploymentリソースはappsとextensionsに対応していることが分かる。
つまりapps/*extensions/* のapiVersionを指定してやればいい。

既存のapiVersionはコマンドで出力できる。

$ kubectl api-versions  | grep apps
apps/v1
apps/v1beta1
apps/v1beta2
$ kubectl api-versions  | grep extensions
apiextensions.k8s.io/v1beta1
extensions/v1beta1

いずれかのapiVersionをyamlに書いてやる。

deploytest.yaml
apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: deploy-test
  namespace: test
spec:
  replicas: 2
  template:
    metadata:
      labels: 
        app: pod-example
    spec:
      containers:
      - name: nginx
        image: nginx:1.10
        ports:
        - containerPort: 80

その後、コマンドからDeploymentを作成。

$ kubectl create -f deploytest.yaml
deployment.apps/deploy-test created

よさげ。

7
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?