ICTSC2025 一次予選 問題解説: 問31

問31

以下は、Kubernetes のマニフェスト一部を抜き出したものである。

spec:
  schedule: "30 7,12,17 * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
            - name: hogehoge
              image: registry.example.com/hogehoge:latast

以下の選択肢の中から正しいものを全て選べ。なお、Kubernetes v1.33 を想定し、Feature Gate は無効とする。また、registry.example.com/hogehoge:latast は、正常にpullできることを確認している。

選択肢(複数選択)

  1. job が起動する度にレジストリに対してイメージの digest が更新されていないか確認する
  2. 2回目以降の起動では、イメージを pull しない
  3. 毎回イメージを pull する
  4. ローカルにイメージのキャッシュがある限り、コンテナは起動し続ける

解説

この問題は Kuberenetes の imagePullPolicyCronJob についての挙動を問う問題でした。

imagePullPolicy について公式のドキュメントを確認すると以下のようにあります。

Default image pull policy
When you (or a controller) submit a new Pod to the API server, your cluster sets the imagePullPolicy field when specific conditions are met:
if you omit the imagePullPolicy field, and you specify the digest for the container image, the imagePullPolicy is automatically set to IfNotPresent.
if you omit the imagePullPolicy field, and the tag for the container image is :latest, imagePullPolicy is automatically set to Always.
if you omit the imagePullPolicy field, and you don't specify the tag for the container image, imagePullPolicy is automatically set to Always.
if you omit the imagePullPolicy field, and you specify a tag for the container image that isn't :latest, the imagePullPolicy is automatically set to IfNotPresent.

ここから、imagePullPolicy を明示的に指定しない場合、タグが latest であれば imagePullPolicyAlways(常にダイジェストを確認、変更があれば pull する)、latest 以外であれば imagePullPolicyIfNotPresent(ローカルにイメージがなければ pull する)ことがわかります。

今回の問題ではタグが latest ではなく latastと書き間違えられているので、imagePullPolicyIfNotPresent となります。

IfNotPresent の場合、初回にイメージを pull した後はレジストリからイメージを pull することも、digest を確認することはありません。
つまり、ローカルにイメージのキャッシュがある限り、コンテナは起動し続ける、が正解となります。

選択肢1は、先ほどの digest を確認することはない、という点で誤りがあります。
選択肢2は、2回目以降の起動においてもローカルにキャッシュがないノードの場合に pull する可能性があるため誤りです。
選択肢3は、毎回イメージを pull する、という点で誤りです。起動するノードにイメージがあれば pull しません。
したがって、正答は選択肢4となります。