概述

在我们搭建完k8s的时候,有时需要启动个centos系统的pod,打印日志,不可避免的就需要在command字段里是循环。

操作

示例1

死循环输出“hello”

        command:
            - /bin/sh
            - -c
            - while true; do echo hello; sleep 1;done      

完整发布文件centos-deploy.yaml

apiVersion: apps/v1
kind: Deployment
metadata:

  labels:
    k8s-app: centos
    qcloud-app: centos
  name: centos


spec:

  replicas: 1
  selector:
    matchLabels:
      k8s-app: centos
      qcloud-app: centos
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
    type: RollingUpdate
  template:
    metadata:
      labels:
        k8s-app: centos
        qcloud-app: centos
    spec:
      containers:

      - image: centos:7
        imagePullPolicy: Always
        name: centos
        command:
            - /bin/sh
            - -c
            - while true; do echo hello; sleep 1;done          
          
         

 

 

示例2

死循环维持pod运行

        - command:
            - sleep
            - '3600'

 

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐