【问题标题】:How to configure automatic pod reboot in Kubernetes if another pod reboots如果另一个 pod 重新启动,如何在 Kubernetes 中配置自动 pod 重启
【发布时间】:2021-07-30 08:15:23
【问题描述】:

我有两个 pod,第一个 pod 重启后,另一个应该在它之后自动重启。 Pod 是使用不同的部署创建的

【问题讨论】:

    标签: kubernetes kubernetes-pod


    【解决方案1】:

    您可以用 python 或任何语言写下脚本,一旦重新启动,您的脚本将 以这种方式推出第二个部署 POD 的部署将重新启动

    您可以在一个 POD 内或作为部署运行脚本,这将持续监控 Deployment-1 并在 中发生任何更改时重新启动 deployment-2部署-1

    python 客户端示例

    import logging
    import time
    from kubernetes import client, config, watch
    import json
    import requests
    import time
    logger = logging.getLogger('k8s_events')
    logger.setLevel(logging.DEBUG)
    
    # If running inside pod
    config.load_incluster_config()
    
    # If running locally
    #config.load_kube_config()
    
    v1 = client.CoreV1Api()
    v1ext = client.ExtensionsV1beta1Api() 
    
    w = watch.Watch()
    
    mydict={}
    
    webhook_url = '';
    
    while True:
        pod_list= v1.list_namespaced_pod("default");
    

    此外,您可以编写检查重启计数的逻辑。

    https://kubernetes.io/docs/tasks/administer-cluster/access-cluster-api/

    官方库列表:https://kubernetes.io/docs/reference/using-api/client-libraries/#officially-supported-kubernetes-client-libraries

    【讨论】:

      猜你喜欢
      • 2020-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-22
      相关资源
      最近更新 更多