zoukankan      html  css  js  c++  java
  • K8S-yaml里初始化容器

    初始化容器:

    • 验证业务应用依赖的组件是否均已启动
    • 修改目录的权限
    • 调整系统参数
          initContainers:
          - command:
            - /sbin/sysctl
            - -w
            - vm.max_map_count=262144
            image: alpine:3.6
            imagePullPolicy: IfNotPresent
            name: elasticsearch-logging-init
            resources: {}
            securityContext:
              privileged: true
          - name: fix-permissions
            image: alpine:3.6
            command: ["sh", "-c", "chown -R 1000:1000 /usr/share/elasticsearch/data"]
            securityContext:
              privileged: true
            volumeMounts:
            - name: elasticsearch-logging
              mountPath: /usr/share/elasticsearch/data
    
    

    验证Pod生命周期:

    apiVersion: v1
    kind: Pod
    metadata:
      name: demo-start-stop
      namespace: luffy
      labels:
        component: demo-start-stop
    spec:
      initContainers:
      - name: init
        image: busybox
        command: ['sh', '-c', 'echo $(date +%s): INIT >> /loap/timing']
        volumeMounts:
        - mountPath: /loap
          name: timing
      containers:
      - name: main
        image: busybox
        command: ['sh', '-c', 'echo $(date +%s): START >> /loap/timing;
    sleep 10; echo $(date +%s): END >> /loap/timing;']
        volumeMounts:
        - mountPath: /loap 
          name: timing
        livenessProbe:
          exec:
            command: ['sh', '-c', 'echo $(date +%s): LIVENESS >> /loap/timing']
        readinessProbe:
          exec:
            command: ['sh', '-c', 'echo $(date +%s): READINESS >> /loap/timing']
        lifecycle:
          postStart:
            exec:
              command: ['sh', '-c', 'echo $(date +%s): POST-START >> /loap/timing']
          preStop:
            exec:
              command: ['sh', '-c', 'echo $(date +%s): PRE-STOP >> /loap/timing']
      volumes:
      - name: timing
        hostPath:
          path: /tmp/loap
    
    

    创建pod测试:

    $ kubectl create -f demo-pod-start.yaml
    
    ## 查看demo状态
    $ kubectl -n luffy get po -o wide -w
    
    ## 查看调度节点的/tmp/loap/timing
    $ cat /tmp/loap/timing
    1585424708: INIT
    1585424746: START
    1585424746: POST-START
    1585424754: READINESS
    1585424756: LIVENESS
    1585424756: END
    
    
  • 相关阅读:
    ubuntu下安装VMware tools
    ubuntu 输入su提示认证失败的解决方法
    Squishy Bird 压扁小鸟
    js 毫秒转日期(yy-MM-dd hh:mm:ss)
    js--使用构造器函数来新建对象及操作
    css中table样式
    js 字符串截取
    JavaScript中Math--random()/floor()/round()/ceil()
    canvas draw a image
    html5 canvas simple drawing
  • 原文地址:https://www.cnblogs.com/dinghc/p/14384822.html
Copyright © 2011-2022 走看看