LoginSignup
174
105

More than 1 year has passed since last update.

Kubernetesの apiVersion に何を書けばいいか

Last updated at Posted at 2019-02-20

Kubernetes の apiVersionの調べ方

  • リソース (Deployment, Service etc..) のapiVersionに何を書けばいいのか?
    • apps ? apps/v1 ? apps/v1beta1 ??
  • Kubernetesの新しいAPIを試したいときどうすればいいのか?

のやり方が意外とどこにも書いてないのでまとめ。

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

それぞれのケースで、

ケース 書き方
特定のAPIGROUPに属している場合 apiVersion: (APIGROUP)/(APIVERSION)
特定のAPIGROUPに属していない場合(= Core groupに属する) apiVersion: v1

と記述する必要がある。

1. api-resources コマンドで、リソースとAPI GROUPの対応を調べる

リソースと APIGROUP の対応は kubectl api-resources で出力できる。

注意:

  • 古いkubectlでは実装されていない。 v1.12で存在確認
  • 現在のコンテキストにおける情報らしいので、複数のクラスタを扱っているときは接続先に注意
$ kubectl api-resources 
NAME                              SHORTNAMES   APIGROUP                       NAMESPACED   KIND
bindings                                                                      true         Binding
componentstatuses                 cs                                          false        ComponentStatus
configmaps                        cm                                          true         ConfigMap
endpoints                         ep                                          true         Endpoints
events                            ev                                          true         Event
limitranges                       limits                                      true         LimitRange
namespaces                        ns                                          false        Namespace
nodes                             no                                          false        Node
persistentvolumeclaims            pvc                                         true         PersistentVolumeClaim
persistentvolumes                 pv                                          false        PersistentVolume
pods                              po                                          true         Pod
podtemplates                                                                  true         PodTemplate
replicationcontrollers            rc                                          true         ReplicationController
resourcequotas                    quota                                       true         ResourceQuota
secrets                                                                       true         Secret
serviceaccounts                   sa                                          true         ServiceAccount
services                          svc                                         true         Service
mutatingwebhookconfigurations                  admissionregistration.k8s.io   false        MutatingWebhookConfiguration
validatingwebhookconfigurations                admissionregistration.k8s.io   false        ValidatingWebhookConfiguration
customresourcedefinitions         crd,crds     apiextensions.k8s.io           false        CustomResourceDefinition
apiservices                                    apiregistration.k8s.io         false        APIService
controllerrevisions                            apps                           true         ControllerRevision
daemonsets                        ds           apps                           true         DaemonSet
deployments                       deploy       apps                           true         Deployment
replicasets                       rs           apps                           true         ReplicaSet

Deploymentappsextensions に属していることがわかる。

$ kubectl api-resources | grep Deployment
deployments                       deploy       apps                           true         Deployment
deployments                       deploy       extensions                     true         Deployment

なぜ2つあるのかというと、移行過渡期のため。
https://github.com/kubernetes/kubernetes/issues/61430

ということで apps を使えばいいらしい。

APIGROUPが空のリソースは Core groupに属するので、 apiVersion: v1 でよい。

それぞれのAPIGROUPで利用可能なversionを調べる

Core以外のAPIGROUPに属しているもののうち、 どのバージョンが使えるかは kubectl api-versions で出力することができる。

注意:

  • 現在のコンテキストにおける情報らしいので、複数のクラスタを(ry
$ kubectl api-versions    
admissionregistration.k8s.io/v1beta1
apiextensions.k8s.io/v1beta1
apiregistration.k8s.io/v1
apiregistration.k8s.io/v1beta1
apps/v1
apps/v1beta1
apps/v1beta2
authentication.k8s.io/v1
authentication.k8s.io/v1beta1
authorization.k8s.io/v1
authorization.k8s.io/v1beta1
autoscaling/v1
autoscaling/v2beta1
batch/v1
batch/v1beta1
certificates.k8s.io/v1beta1
cloud.google.com/v1beta1
extensions/v1beta1
metrics.k8s.io/v1beta1
networking.k8s.io/v1
policy/v1beta1
rbac.authorization.k8s.io/v1
rbac.authorization.k8s.io/v1beta1
scalingpolicy.kope.io/v1alpha1
scheduling.k8s.io/v1beta1
storage.k8s.io/v1
storage.k8s.io/v1beta1
v1

先程の apps groupに絞ってみると、

$ kubectl api-versions  | grep apps
apps/v1
apps/v1beta1
apps/v1beta2

ということで、上記のいずれかを使用すればいいらしい。

複数バージョンのうち、何を使うか?

公式のAPIリファレンスドキュメントを参照する。

例えばDeploymentapps/v1beta2 では
https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.10/#deployment-v1beta2-apps
のように、バージョンによって機能差分があることがわかる。

<2022-07-20 update>
Deploymentはv1実装でされているので、betaがとれている。
例えば現時点では、HorizontalPodAutoscaler には複数バージョンが存在し、それぞれ機能差分があるので、公式ドキュメントを確認する
スクリーンショット 2022-07-20 15.39.21.png

ドキュメントを見て、適切なバージョンを選択する。

174
105
1

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
174
105