KUBERNETES04_下载策略、私有仓库下载、env、command、生命周期容器钩子、资源限制(二)

③. env、command


  • ①. env指定环境变量,这里以一个部署MYSQL为例


kind: Pod
apiVersion: v1
metadata:
  name: my-mysql
  namespace: hello
  labels:
     name: tangzhi
spec:  # 指定规格信息
  containers:  # 指定要启动一个什么样的容器
  ## docker run -e = env   --name=name -v=volumeMounts -w /usr/  /bin/bash
  - image: mysql:5.7.34  #指定镜像
    name: mysql  #容器的名字 数据就在容器里面  docker run mysql.
    # ports: #指定容器暴露哪些端口  -p  
    env:
     - name: MYSQL_ROOT_PASSWORD
       value: "123456"
     - name: MYSQL_DATABASE
       value: "tang"
    workingDir: "/usr/" # Dockerfiel WORKDIR
    #volumeMounts: 挂载


②. command


[root@k8s-master k8syaml]# kubectl explain pod.spec.containers.command
KIND:     Pod
VERSION:  v1

FIELD:    command <[]string>

DESCRIPTION:
     Entrypoint array. Not executed within a shell. The docker image's
     ENTRYPOINT is used if this is not provided. Variable references $(VAR_NAME)
     are expanded using the container's environment. If a variable cannot be
     resolved, the reference in the input string will be unchanged. The
     $(VAR_NAME) syntax can be escaped with a double $$, ie: $$(VAR_NAME).
     Escaped references will never be expanded, regardless of whether the
     variable exists or not. Cannot be updated. More info:
     https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#running-a-command-in-a-shell


kind: Pod
apiVersion: v1
metadata:
  name: my-command-test
  namespace: hello
spec:  # 指定规格信息
  containers:  # 指定要启动一个什么样的容器
  - image: nginx  #指定镜像。默认会启动一个nginx容器
    name: command-test  
    command:    # 以这里为准  ## redis 主节点  redis 启动命令
      - /bin/sh
      - -c
      - "echo $(msg);"
    env:
      - name: msg
        value: "hello msg"   ## Dockerfile  CMD  能用到
    # 直接覆盖容器的默认命令  Dockerfile  ENTRYPOINT CMD 指定容器的启动命令


KUBERNETES04_下载策略、私有仓库下载、env、command、生命周期容器钩子、资源限制(二)

上一篇:KUBERNETES03_k8s对象是什么、如何管理、命名空间、代码自动补全提示(一)


下一篇:div图片和内容都居中应用