はじめに
オブジェクト指向でSOLIDの原則というものがあると初めて知った。 見てみると、ソフトウェアを開発する中で体で覚えてきたものが明文化されていたので、頭の中がスッキリとまとまった感じがして、ちょっと感動。
OpenShiftの環境で利用されるSource-To-Image (S2I)の仕様などの参考情報。
s2i builder image requirements
How to use a non-builder image for the final application image
s2i command line interface
OpenShiftの研修を受講。 KubernetesのDeploymentとOpenShiftのDeploymentConfigの違いがよく分からなかったので、調べてみた。
自分でまとめるまでもなく、以下のブログによくまとまっていた。
DeploymentConfigはOpenShift固有のものだが、後にKubernetesがほぼ同等のDeploymentを導入したので、現在ではOpenShiftでもDeploymentが推奨とのこと。
OpenShift 4.5以降ではデフォルトでDeploymentが利用されるようになっている模様。
OpenShift 4.5以降でDeploymentConfigを利用する場合は、例えばコマンドoc new-app
の実行の際にオプション--as-deployment-config
を付与するなど、明示的な指定が必要そう。
OpenShift Container Platform 4.5 > Applications > Deployments > Understanding Deployments and DeploymentConfigs
OpenShift Container Platform > 4.5 > アプリケーション > 第3章 デプロイメント > 3.1. Deployment および DeploymentConfig オブジェクトについて
What is the different between openshift deploymentconfig and kubernetes deployment
コマンドkubectl
を利用するときに、リソースの省略形が利用されることがある。
例えば、services
は以下のようにsvc
と省略できる。
$ kubectl get svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 140d nginx ClusterIP None <none> 80/TCP 7h19m
省略形の一覧は、以下のようにコマンドkubectl api-resources
で確認できる。
結果はKubernetesのバージョンによって違うと思われる。
$ 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/v1beta1 true CronJob jobs batch/v1 true Job certificatesigningrequests csr certificates.k8s.io/v1 false CertificateSigningRequest leases coordination.k8s.io/v1 true Lease endpointslices discovery.k8s.io/v1beta1 true EndpointSlice events ev events.k8s.io/v1 true Event ingresses ing extensions/v1beta1 true Ingress 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/v1beta1 false RuntimeClass poddisruptionbudgets pdb policy/v1beta1 true PodDisruptionBudget podsecuritypolicies psp policy/v1beta1 false PodSecurityPolicy 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 storageclasses sc storage.k8s.io/v1 false StorageClass volumeattachments storage.k8s.io/v1 false VolumeAttachment
外出先とかだと、その場で使えるようなgitが入った開発環境が準備できないことがある。 GitHubのWeb UIからある程度ファイル操作が可能だが、現時点ではファイルに実行権はつけられないようだ。
OpenShiftではDockerの代わりにPodmanが利用されるため、開発環境でPodmanを利用することになった。 そのため、Ubuntu 20.04 LTSでPodmanとPodman-composeのインストールした記録を残しておく。
基本的には、Podmanの公式サイトのインストール手順をなぞっているだけ。 Ubuntu 20.10以降では公式のaptのリポジトリにPodmanが含まれているようだが、今回の環境はUbuntu 20.04 LTSなので追加のリポジトリを登録する必要がある。
. /etc/os-release echo "deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_${VERSION_ID}/ /" | sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list curl -L https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_${VERSION_ID}/Release.key | sudo apt-key add -
そして、Ubuntu 20.04 LTSを最新状態にしたあとで、Podmanをインストールする。 最新状態にしないと、インストールに失敗する場合があるらしい。
sudo apt-get update sudo apt-get -y upgrade sudo apt-get -y install podman
Podman Composeはpipを利用してインストールする。 今回は、システムレベルでPodman Composeをインストールしたいので、sudoコマンド経由でpipを実行する。
$ sudo apt install python3-pip $ sudo pip3 install podman-compose
$ podman run hello-world Completed short name "hello-world" with unqualified-search registries (origin: /etc/containers/registries.conf) Trying to pull docker.io/library/hello-world:latest... Getting image source signatures Copying blob 0e03bdcc26d7 done Copying config bf756fb1ae done Writing manifest to image destination Storing signatures Hello from Docker! (以下略)
Podman > Getting Started with Podman > Podman Installation Instructions
Podman Compose