4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

k8sのマニフェストでPodのdocker imageのCMDを書き換えるときはcommandじゃダメ

Posted at

ちゃんとドキュメントを読めば書いてありました。
ただ、間違えやすそうなのでメモ。

結論

  • マニフェストのcommandはDockerfileのENTRYPOINT
  • マニフェストのargsはDockerfileのCMD
apiVersion: v1
kind: Pod
metadata:
  name: command-demo
  labels:
    purpose: demonstrate-command
spec:
  containers:
  - name: command-demo-container
    image: debian
    command: ["printenv"]                    # こっちはENTRYPOINT
    args: ["HOSTNAME", "KUBERNETES_PORT"]    # こっちはCMD
  restartPolicy: OnFailure

注意

また、command・argsをそれぞれ定義したかどうかで挙動が変わるので注意。

Dockerfileが

  • ENTRYPOINT: echo
  • CMD: HOSTNAME

だった場合

command args 実行されるコマンド
未定義 未定義 echo HOSTNAME
printenv 未定義 printenv
未定義 KUBERNETES_PORT echo KUBERNETES_PORT
printenv KUBERNETES_PORT printenv KUBERNETES_PORT

となる。

4
1
0

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
4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?