インフラ系SEの技術メモ

雑なエンジニアが低信頼性のメモを書いています。参考程度にとどめてください。

なぜOpenshiftではnew-appをすると勝手にServiceまでできてしまうのか

Openshiftは色々勝手にやってくれる

結論から言うと、Openshiftはs2iという機能で事前に登録済のイメージを起動しようとするとよしなにやってくれます。

まずプロジェクトを作ると

$ oc new-project xx
You can add applications to this project with the 'new-app' command. For example, try:
    oc new-app ruby~https://github.com/sclorg/ruby-ex.git
to build a new example application in Ruby. Or use kubectl to deploy a simple Kubernetes application:
    kubectl create deployment hello-node --image=gcr.io/hello-minikube-zero-install/hello-node

と例文が出ますが、前者と後者では動きが全く違う...

ocとkubectl

後者はわかりやすくてイメージをdeploymentにするだけですよね。要はPodだけじゃなくてDeploymentまで作ってくれる。
でも前者を試しに打つと

$ oc new-app ruby~https://github.com/sclorg/ruby-ex.git
--> Found image ef95b87 (3 months old) in image stream "openshift/ruby" under tag "2.6" for "ruby"
    Ruby 2.6
--> Creating resources ...
    imagestream.image.openshift.io "ruby-ex" created
    buildconfig.build.openshift.io "ruby-ex" created
    deployment.apps "ruby-ex" created
    service "ruby-ex" created
...

めっちゃ色々できてる。DeploymentはまだしもServiceまで。

何が起きている?

JSONに出して中を見るとわかりやすい。

$ cat test.json | grep kind
    "kind": "List",
            "kind": "ImageStream",
            "kind": "BuildConfig",
                            "kind": "ImageStreamTag",
                        "kind": "ImageStreamTag",
            "kind": "Deployment",
                    "image.openshift.io/triggers": "[{\"from\":{\"kind\":\"ImageStreamTag\",\"name\":\"ruby-ex:latest\"},\"fieldPath\":\"spec.template.spec.containers[?(@.name==\\\"ruby-ex\\\")].image\"}]",
            "kind": "Service",

なんとKindだらけ。-n openshift にて is(イメージストリーム)に存在するイメージをnew appするとよしなに色々とやってくれるんですね。メモメモ。