00002.通过OC Rest API部署image

2022-07-27  本文已影响0人  笑着字太黑
基本信息(辅助理解):
  ImageStream.name:nodestart
  ImageStreamTag.tag:1.0.0
  (deployment|service|route).name:lt-app

====create image:
  暂略

====create deployment:
https://[host:port]/apis/apps/v1/namespaces/[namespace]/deployments
{
  "metadata":{
    "name": "lt-app",
    "annotations":{
      "alpha.image.policy.openshift.io/resolve-names": "*",
      "deployment.kubernetes.io/revision": "1",
      "image.openshift.io/triggers": "[{\"from\":{\"kind\":\"ImageStreamTag\",\"name\":\"nodestart:1.0.0\",\"namespace\":\"[namespace]\"},\"fieldPath\":\"spec.template.spec.containers[?(@.name==\\\"nodestart\\\")].image\",\"pause\":\"false\"}]",
      "openshift.io/generated-by": "OpenShiftWebConsole"
    }
  },
  "spec":{
    "selector": {"matchLabels": {"app": "lt-app"}},
  
    "template":{
      "metadata":{"labels":{"app": "lt-app"}},
      "spec":{
        "containers":[{   "image":"image-registry.openshift-image-registry.svc:5000/[namespace]/nodestart@sha256:f5844d3c7c4b6adac6c019998720b9dd02dc745c25bcbe0e36cf02d1ab8d2838",
          "name": "nodestart",
          "ports":[
            {
              "containerPort":8080,
              "protocol": "TCP"
            }
          ]  
        }]
      }
    }
  }
}

metadata.annotations.image.openshift.io/triggers:(注意值的前后有双引号,是一个JSON格式的字符串)
  ·通过关联到spec.template.spec.containers[?].image,来关联到image
  ·[\"]替换为单引号也是可以的。
  ·spec.template.spec.containers[?].name的值应该是可以随便写的,但是要注意跟triggers里面的设定内容保存一致。

spec.template.spec.containers[?].image:
  这里是前面步骤创建好的ImageStreamTag,保存在OC内部dockerImageRepository

====create service:
https://[host:port]/api/v1/namespaces/[namespace]/services
{
  "metadata":{"name": "lt-app"},
  "spec":{
      "ports": [{
        "name": "8080-tcp",
        "protocol": "TCP",
        "port": 8080,
        "targetPort": 8080
      }],
      "selector":{
        "app": "lt-app"
      }
  }
}

spec.selector:
  Route service traffic to pods with label keys and values matching this selector.
  我理解是前面步骤创建的deployment的名字,但是不确定


====create route:
https://[host:port]/apis/route.openshift.io/v1/namespaces/[namespace]/routes/
{
   "metadata": {"name": "lt-app"},
   "spec": {
      "to": {
         "kind": "Service",
         "name": "lt-app"
      },
      "tls": {
        "termination": "edge",
        "insecureEdgeTerminationPolicy": "Redirect"
      }
   }
}

spec.to.name:
  前面步骤创建好的service的名字
spec.tls:
  有这个字段就是https可访问,没有就是http可访问
spec.tls.insecureEdgeTerminationPolicy:redirect:
  收到http请求时会重定向到https,好像只有edge的时候才可以设定。没有具体测试不确定
上一篇 下一篇

猜你喜欢

热点阅读