tonylight2016

kube-client-api

Jan 26th, 2021 (edited)
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. from kubernetes import config
  2. from kubernetes.client import Configuration
  3. from kubernetes.client.api import core_v1_api
  4. from kubernetes.client.rest import ApiException
  5. from kubernetes.stream import stream
  6.  
  7.  
  8. def main():
  9. config.load_kube_config()
  10. try:
  11. core_v1 = core_v1_api.CoreV1Api()
  12. resp = core_v1.read_namespaced_pod(name='transcode-api-2zvb2',namespace='default')
  13. print(resp.spec.containers[0].image)
  14. resp.spec.containers[0].image = '192.168.1.179:5000/wondertek/f:v3.0.0_d1_k8s_1_14_5.20201215093847'
  15. pod_manifest = {
  16. 'apiVersion': 'v1',
  17. 'kind': 'Pod',
  18. 'metadata': {'name':'transcode-api-12346'},
  19. 'spec': resp.spec
  20.  
  21. }
  22. #core_v1.delete_namespaced_pod(name='transcode-api-123456', namespace='default')
  23. core_v1.create_namespaced_pod(body=pod_manifest, namespace='default')
  24. except ApiException as e:
  25. print(e)
  26. if e.status != 404:
  27. print("Unknown error: %s" % e)
  28. exit(1)
  29.  
  30.  
Add Comment
Please, Sign In to add comment