概要
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
よさげ。