概要
Kubernetesのマニフェストに記載するapiVersionを確認します。
最小限のマニフェスト
KubernetesでPodを稼働させる為の最小限のマニフェストです。これより削るとapplyが失敗します。コンテナイメージにnginxを使用していますが、centosでもAlpineでも同様です。
root@k8s-01:~# vim /root/k8s/yaml/nginx-minimum.yaml apiVersion: v1 kind: Pod metadata: name: nginx-pod spec: containers: - name: nginx image: nginx root@k8s-01:~# kubectl apply -f /root/k8s/yaml/nginx-minimum.yaml pod/nginx-pod created
apiVersion
apiVersionは各オブジェクト(kindで指定するPod, Deployment, Service…etc)のバージョンであり、Kubernetesのマニフェストで必須項目です。
apiVersionの指定
設定値は”kubectl api-resources”で確認します。前述のnginx-minimum.yamlでは、”kind: Pod”を指定している為、Podで抽出すると、apiVersionはv1であることが分かります。3カラム目がapiVersion、5カラム目がkindです。利用するk8sで指定されたバージョンでしかしようできないのであれば、いちいちマニフェストでの指定は意味がないのではないか?とも思いますが、おそらくバージョンアップでv2が登場した際にv1とv2も選択できるようにすることで、移行をスムーズにする為ではないかと思います。
root@k8s-01:~# kubectl api-resources | grep Pod
pods po v1 true Pod
podtemplates v1 true PodTemplate
horizontalpodautoscalers hpa autoscaling/v1 true HorizontalPodAutoscaler
poddisruptionbudgets pdb policy/v1 true PodDisruptionBudget
podsecuritypolicies psp policy/v1beta1 false PodSecurityPolicy
その他の例として、”kind: Deployment”の場合は、”apps/v1″となります。appsはapiGroupとなり、apiGroup/apiVersionで記載が必要です。
root@k8s-01:~# kubectl api-resources | grep Deployment
deployments deploy apps/v1 true Deployment
Appendix
API Resources
root@k8s-01:~# kubectl version --short Client Version: v1.22.2 Server Version: v1.22.3 root@k8s-01:~# kubectl api-resources NAME SHORTNAMES APIVERSION NAMESPACED KIND bindings v1 true Binding componentstatuses cs v1 false ComponentStatus configmaps cm v1 true ConfigMap endpoints ep v1 true Endpoints events ev v1 true Event limitranges limits v1 true LimitRange namespaces ns v1 false Namespace nodes no v1 false Node persistentvolumeclaims pvc v1 true PersistentVolumeClaim persistentvolumes pv v1 false PersistentVolume pods po v1 true Pod podtemplates v1 true PodTemplate replicationcontrollers rc v1 true ReplicationController resourcequotas quota v1 true ResourceQuota secrets v1 true Secret serviceaccounts sa v1 true ServiceAccount services svc v1 true Service mutatingwebhookconfigurations admissionregistration.k8s.io/v1 false MutatingWebhookConfiguration validatingwebhookconfigurations admissionregistration.k8s.io/v1 false ValidatingWebhookConfiguration customresourcedefinitions crd,crds apiextensions.k8s.io/v1 false CustomResourceDefinition apiservices apiregistration.k8s.io/v1 false APIService controllerrevisions apps/v1 true ControllerRevision daemonsets ds apps/v1 true DaemonSet deployments deploy apps/v1 true Deployment replicasets rs apps/v1 true ReplicaSet statefulsets sts apps/v1 true StatefulSet tokenreviews authentication.k8s.io/v1 false TokenReview localsubjectaccessreviews authorization.k8s.io/v1 true LocalSubjectAccessReview selfsubjectaccessreviews authorization.k8s.io/v1 false SelfSubjectAccessReview selfsubjectrulesreviews authorization.k8s.io/v1 false SelfSubjectRulesReview subjectaccessreviews authorization.k8s.io/v1 false SubjectAccessReview horizontalpodautoscalers hpa autoscaling/v1 true HorizontalPodAutoscaler cronjobs cj batch/v1 true CronJob jobs batch/v1 true Job certificatesigningrequests csr certificates.k8s.io/v1 false CertificateSigningRequest leases coordination.k8s.io/v1 true Lease bgpconfigurations crd.projectcalico.org/v1 false BGPConfiguration bgppeers crd.projectcalico.org/v1 false BGPPeer blockaffinities crd.projectcalico.org/v1 false BlockAffinity caliconodestatuses crd.projectcalico.org/v1 false CalicoNodeStatus clusterinformations crd.projectcalico.org/v1 false ClusterInformation felixconfigurations crd.projectcalico.org/v1 false FelixConfiguration globalnetworkpolicies crd.projectcalico.org/v1 false GlobalNetworkPolicy globalnetworksets crd.projectcalico.org/v1 false GlobalNetworkSet hostendpoints crd.projectcalico.org/v1 false HostEndpoint ipamblocks crd.projectcalico.org/v1 false IPAMBlock ipamconfigs crd.projectcalico.org/v1 false IPAMConfig ipamhandles crd.projectcalico.org/v1 false IPAMHandle ippools crd.projectcalico.org/v1 false IPPool ipreservations crd.projectcalico.org/v1 false IPReservation kubecontrollersconfigurations crd.projectcalico.org/v1 false KubeControllersConfiguration networkpolicies crd.projectcalico.org/v1 true NetworkPolicy networksets crd.projectcalico.org/v1 true NetworkSet endpointslices discovery.k8s.io/v1 true EndpointSlice events ev events.k8s.io/v1 true Event flowschemas flowcontrol.apiserver.k8s.io/v1beta1 false FlowSchema prioritylevelconfigurations flowcontrol.apiserver.k8s.io/v1beta1 false PriorityLevelConfiguration network-attachment-definitions net-attach-def k8s.cni.cncf.io/v1 true NetworkAttachmentDefinition ingressclasses networking.k8s.io/v1 false IngressClass ingresses ing networking.k8s.io/v1 true Ingress networkpolicies netpol networking.k8s.io/v1 true NetworkPolicy runtimeclasses node.k8s.io/v1 false RuntimeClass apiservers operator.tigera.io/v1 false APIServer imagesets operator.tigera.io/v1 false ImageSet installations operator.tigera.io/v1 false Installation tigerastatuses operator.tigera.io/v1 false TigeraStatus poddisruptionbudgets pdb policy/v1 true PodDisruptionBudget podsecuritypolicies psp policy/v1beta1 false PodSecurityPolicy bgpconfigurations bgpconfig,bgpconfigs projectcalico.org/v3 false BGPConfiguration bgppeers projectcalico.org/v3 false BGPPeer caliconodestatuses caliconodestatus projectcalico.org/v3 false CalicoNodeStatus clusterinformations clusterinfo projectcalico.org/v3 false ClusterInformation felixconfigurations felixconfig,felixconfigs projectcalico.org/v3 false FelixConfiguration globalnetworkpolicies gnp,cgnp,calicoglobalnetworkpolicies projectcalico.org/v3 false GlobalNetworkPolicy globalnetworksets projectcalico.org/v3 false GlobalNetworkSet hostendpoints hep,heps projectcalico.org/v3 false HostEndpoint ippools projectcalico.org/v3 false IPPool ipreservations projectcalico.org/v3 false IPReservation kubecontrollersconfigurations projectcalico.org/v3 false KubeControllersConfiguration networkpolicies cnp,caliconetworkpolicy,caliconetworkpolicies projectcalico.org/v3 true NetworkPolicy networksets netsets projectcalico.org/v3 true NetworkSet profiles projectcalico.org/v3 false Profile clusterrolebindings rbac.authorization.k8s.io/v1 false ClusterRoleBinding clusterroles rbac.authorization.k8s.io/v1 false ClusterRole rolebindings rbac.authorization.k8s.io/v1 true RoleBinding roles rbac.authorization.k8s.io/v1 true Role priorityclasses pc scheduling.k8s.io/v1 false PriorityClass csidrivers storage.k8s.io/v1 false CSIDriver csinodes storage.k8s.io/v1 false CSINode csistoragecapacities storage.k8s.io/v1beta1 true CSIStorageCapacity storageclasses sc storage.k8s.io/v1 false StorageClass volumeattachments storage.k8s.io/v1 false VolumeAttachment
API Versions
root@k8s-01:~# kubectl version --short Client Version: v1.22.2 Server Version: v1.22.3 root@k8s-01:~# kubectl api-versions admissionregistration.k8s.io/v1 apiextensions.k8s.io/v1 apiregistration.k8s.io/v1 apps/v1 authentication.k8s.io/v1 authorization.k8s.io/v1 autoscaling/v1 autoscaling/v2beta1 autoscaling/v2beta2 batch/v1 batch/v1beta1 certificates.k8s.io/v1 coordination.k8s.io/v1 crd.projectcalico.org/v1 discovery.k8s.io/v1 discovery.k8s.io/v1beta1 events.k8s.io/v1 events.k8s.io/v1beta1 flowcontrol.apiserver.k8s.io/v1beta1 k8s.cni.cncf.io/v1 networking.k8s.io/v1 node.k8s.io/v1 node.k8s.io/v1beta1 operator.tigera.io/v1 policy/v1 policy/v1beta1 projectcalico.org/v3 rbac.authorization.k8s.io/v1 scheduling.k8s.io/v1 storage.k8s.io/v1 storage.k8s.io/v1beta1 v1
Kubernetes マニフェストを理解する apiVersion