{"id":10095,"date":"2023-03-22T13:41:09","date_gmt":"2023-03-22T05:41:09","guid":{"rendered":"http:\/\/123.57.164.21\/?p=10095"},"modified":"2023-03-22T13:41:09","modified_gmt":"2023-03-22T05:41:09","slug":"%e3%80%90openshift%e3%80%91%e5%9c%a8openshift%e4%b8%8a%e9%80%9a%e8%bf%87yaml%e9%83%a8%e7%bd%b2%e5%ba%94%e7%94%a8","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=10095","title":{"rendered":"\u3010openshift\u3011\u5728Openshift\u4e0a\u901a\u8fc7yaml\u90e8\u7f72\u5e94\u7528"},"content":{"rendered":"\n<p><strong>\u5728<a rel=\"noreferrer noopener\" href=\"https:\/\/so.csdn.net\/so\/search?q=Openshift&amp;spm=1001.2101.3001.7020\" target=\"_blank\">Openshift<\/a>\u4e0a\u901a\u8fc7yaml\u90e8\u7f72\u5e94\u7528<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p><strong>1.\u901a\u8fc7\u76f4\u63a5\u6267\u884c<a rel=\"noreferrer noopener\" href=\"https:\/\/so.csdn.net\/so\/search?q=yaml&amp;spm=1001.2101.3001.7020\" target=\"_blank\">yaml<\/a><\/strong><\/p>\n\n\n\n<p>\u901a\u8fc7\u5982\u4e0b\u547d\u4ee4\u76f4\u63a5\u6267\u884c<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">oc create -f nginx.yml<\/pre>\n\n\n\n<p><strong>nginx.yml<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">apiVersion: v1\nitems:\n- apiVersion: apps.openshift.io\/v1\n  # okd \u90e8\u7f72\u914d\u7f6e(dc)\uff0c\u4e0e k8s Deployment \u8d44\u6e90\u5bf9\u8c61\u7c7b\u4f3c\uff0c\u4ee5\u542f\u52a8\u591a\u4e2a\u5bb9\u5668\u7684\u65b9\u5f0f\u751f\u6210 pod\n  kind: DeploymentConfig\n  metadata:\n    # \u6807\u7b7e\uff0c\u5728\u67e5\u8be2\u65f6\u5177\u4f53\u8d44\u6e90\u5bf9\u8c61\u65f6\u975e\u5e38\u91cd\u8981\uff0c\u5982\uff1a>oc get dc -l app=nginx\n    labels:\n      app: nginx\n    name: nginx\n    # \u9009\u5b9a\u9879\u76ee\u7a7a\u95f4\n    namespace: test\n  spec:\n    # \u526f\u672c\u6570\uff0c\u5373 nginx app \u90e8\u7f72\u7684\u5b9e\u4f8b\u6570\n    replicas: 1\n    # pod \u7684\u8ba1\u7b97\u8d44\u6e90\u914d\u989d\n    resources:\n      # pod \u80fd\u5206\u914d\u7684\u6700\u5927\u8ba1\u7b97\u8d44\u6e90\n      limits:\n        cpu: 300m\n        memory: 1024Mi\n      # pod \u5206\u914d\u7684\u6700\u5c11\u8ba1\u7b97\u8d44\u6e90\n      requests:\n        cpu: 100m\n        memory: 200Mi\n    # \u9009\u62e9\u5668 Service \u6839\u636e\u6b64\u9879\u6765\u7ed1\u5b9a\u5230 dc\n    selector:\n      name: nginx\n    strategy:\n    #   type: Recreate\n      type: Rolling\n    # dc \u6839\u636e\u6a21\u677f\u91cc\u5185\u5bb9\u521b\u5efa pod\n    template:\n      metadata:\n        labels:\n          app: nginx\n          name: nginx\n          deploymentconfig: nginx\n      spec:\n        # \u5bb9\u5668\u96c6\u5408\n        containers:\n        - capabilities: {}\n          # \u5bb9\u5668\u5185\u73af\u5883\u53d8\u91cf\uff0c\u4e0b\u6587\u7ed9\u8fd9\u4e2a\u5bb9\u5668\u8bbe\u7f6e\u4e86\u65f6\u533a\u548c\u8bed\u8a00\u7684\u73af\u5883\u53d8\u91cf\n          env:\n          - name: TZ\n            value: Asia\/Shanghai\n          - name: LANG\n            value: en_US.UTF-8\n          # \u5bb9\u5668\u4f7f\u7528\u4ec0\u4e48\u955c\u50cf\u90e8\u7f72\uff0c\u5728\u521b\u5efa\u65f6\u9700\u8981\u66ff\u6362\u6210\u5b9e\u9645\u8981\u90e8\u7f72\u7684\u955c\u50cf\n          image: nginx:1.16\n          # \u955c\u50cf\u4e0b\u8f7d\u7b56\u7565\uff0c\u603b\u662f\u4e0b\u8f7d\u6700\u65b0\u7684(Always)\n          imagePullPolicy: IfNotPresent\n          ports: \n            - containerPort: 80\n              protocol: TCP          \n \n          # \u5065\u5eb7\u68c0\u67e5-pod \u662f\u5426\u5b58\u6d3b\n          livenessProbe:\n            failureThreshold: 2\n            # http get \u8bf7\u6c42\u7684\u65b9\u5f0f\u9a8c\u8bc1 pod-ip:80\/\n            httpGet:\n              path: \/\n              port: 80\n            initialDelaySeconds: 60\n            periodSeconds: 60\n            timeoutSeconds: 5\n          name: nginx\n          # \u5065\u5eb7\u68c0\u67e5-pod \u662f\u5426\u5c31\u7eea\n          readinessProbe:\n            httpGet:\n              path: \/\n              port: 80\n            initialDelaySeconds: 3\n            timeoutSeconds: 5\n          # \u5bb9\u5668\u8ba1\u7b97\u8d44\u6e90\u914d\u989d\uff0c\u4e0e pod \u914d\u989d\u7c7b\u4f3c\n          resources:\n            limits:\n              cpu: 300m\n              memory: 1024Mi\n            requests:\n              cpu: 100m\n              memory: 200Mi\n          securityContext:\n            capabilities: {}\n            # privileged: true\n          terminationMessagePath: \/dev\/termination-log\n          # \u5c06 pod \u4e2d\u914d\u7f6e\u7684\u5377\u6302\u8f7d\u5230\u5bb9\u5668\u5185\n        #   volumeMounts:\n        #   - mountPath: \/data\n        #     name: nginx\n        dnsPolicy: ClusterFirst\n        # \u4f7f\u7528\u8282\u70b9\u9009\u62e9\u5668\u5c06\u5e94\u7528\u56fa\u5b9a\u90e8\u7f72\u5230 node1 \u8ba1\u7b97\u8282\u70b9\u4e0a\n        # nodeSelector:\n        #   kubernetes.io\/hostname: node1.app.com\n        restartPolicy: Always\n        # \u914d\u7f6e\u548c\u5b9a\u4e49\u4f7f\u7528\u5b9e\u9645\u8ba1\u7b97\u8282\u70b9\u4e3b\u673a\u6587\u4ef6\u5939\u5730\u5740\u8fd9\u79cd\u7c7b\u578b\u7684\u5377\n        # volumes:\n        # - persistentVolumeClaim:\n        #     claimName: nginx\n        #   name: nginx\n    # pod \u89e6\u53d1\u5668--\u914d\u7f6e\u53d8\u52a8\u89e6\u53d1\u66f4\u65b0\n    triggers:\n    - type: ConfigChange\n- apiVersion: v1\n  # \u670d\u52a1\uff0c\u4e0e k8s \u4e2d service \u4e00\u6837\uff0c\u5c06 dc \u4e0a\u90e8\u7f72\u7684\u5e94\u7528\u66b4\u9732\u7ed9\u5185\u90e8(\u591a)\u6216\u5916\u90e8(\u5c11)\n  kind: Service\n  metadata:\n    labels:\n      app: nginx\n    name: nginx\n  spec:\n    # \u5e94\u7528\u4e2d\u8981\u66b4\u9732\u7684\u7aef\u53e3\u4fe1\u606f\n    ports:\n    - name: http\n      # \u5bf9\u5916\u66b4\u9732\u7684\u7aef\u53e3\n      port: 80\n      protocol: TCP\n      # \u5e94\u7528\u5b9e\u9645\u7aef\u53e3\n      targetPort: 80\n    # \u901a\u8fc7\u9009\u62e9\u5668\u9009\u62e9 dc\n    selector:\n      name: nginx\n    sessionAffinity: None\n    type: ClusterIP\n    \n- apiVersion: route.openshift.io\/v1\n  # OKD \u5e73\u53f0\u7279\u6709\u8d44\u6e90\uff0c\u4e0e k8s \u4e2d ingress \u7c7b\u4f3c\uff0c\u7528\u4e8e\u5c06 service \u6b63\u771f\u66b4\u9732\u7ed9\u5916\u90e8\u4f7f\u7528\uff0c\u4f46\u53ea\u80fd\u4f7f\u7528\u57df\u540d\u8bbf\u95ee\n  kind: Route\n  metadata:\n    labels:\n      app: nginx\n    name: nginx\n  spec:\n    # \u914d\u7f6e\u57df\u540d\n    host: xinchen.app.com\n    to:\n      kind: Service\n      name: nginx\nkind: List\nmetadata: {}<\/pre>\n\n\n\n<p><strong>2. \u901a\u8fc7\u521b\u5efatemplate<\/strong><\/p>\n\n\n\n<p>\u53c2\u8003\u6587\u6863: <a href=\"https:\/\/docs.okd.io\/latest\/dev_guide\/templates.html#writing-templates\">https:\/\/docs.okd.io\/latest\/dev_guide\/templates.html#writing-templates<\/a><\/p>\n\n\n\n<p><strong>\u76f8\u5173\u6307\u4ee4<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># \u4e0a\u4f20\u6a21\u677f\noc create -f &lt;filename> -n &lt;project>\n \n# \u4f7f\u7528\u6a21\u677f\noc process -f nginx-template -p IMAGE_NAME=nginx:1.6 -p REPLICA_COUNT=1\n \n# \u7f16\u8f91\u6a21\u677f\noc edit template &lt;templateName>\n \n# \u5bfc\u51fa\u6a21\u677f\noc get -o yaml --export all > &lt;yaml_filename><\/pre>\n\n\n\n<p><strong>nginx-template.yml<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">kind: Template\napiVersion: v1\nmetadata:\n  name: nginx-template\nobjects: \n  - kind: DeploymentConfig\n    apiVersion: v1\n    metadata: \n      name: nginx\n      namespace: xinchen\n      labels: \n        app: nginx\n    spec:\n      replicas: ${REPLICA_COUNT}\n      selector:\n        name: nginx\n        \n      resources:\n        limits:\n          cpu: 300m\n          memory: 1024Mi\n        requests:\n          cpu: 100m\n          memory: 200Mi\n    \n      strategy:\n        type: Rolling\n    \n      template:\n        metadata:\n          labels:\n            app: nginx\n            name: nginx\n            deploymentconfig: nginx\n        spec:\n        \n          containers:\n          - capabilities: {}\n          \n            env:\n            - name: TZ\n              value: Asia\/Shanghai\n            - name: LANG\n              value: en_US.UTF-8\n \n            image: ${IMAGE_NAME}\n  \n            imagePullPolicy: IfNotPresent\n \n            ports: \n              - containerPort: 80\n                protocol: TCP          \n          \n            livenessProbe:\n              failureThreshold: 2\n              httpGet:\n                path: \/\n                port: 80\n              initialDelaySeconds: 60\n              periodSeconds: 60\n              timeoutSeconds: 5\n            name: nginx\n          \n            readinessProbe:\n              httpGet:\n                path: \/\n                port: 80\n              initialDelaySeconds: 3\n              timeoutSeconds: 5\n          \n            resources:\n              limits:\n                cpu: 300m\n                memory: 1024Mi\n              requests:\n                cpu: 100m\n                memory: 200Mi\n \n            securityContext:\n              capabilities: {}\n              # privileged: true\n            terminationMessagePath: \/dev\/termination-log\n          \n          #   volumeMounts:\n          #   - mountPath: \/data\n          #     name: nginx\n          dnsPolicy: ClusterFirst\n        \n          restartPolicy: Always\n        \n          # volumes:\n          # - persistentVolumeClaim:\n          #     claimName: nginx\n          #   name: nginx\n    # pod \u89e6\u53d1\u5668--\u914d\u7f6e\u53d8\u52a8\u89e6\u53d1\u66f4\u65b0\n      triggers:\n      - type: ConfigChange  \n \n  - kind: Service\n    apiVersion: v1\n    metadata:\n      name: nginx\n      labels:\n        app: nginx    \n    spec:\n      ports: \n      - name: 80-tcp\n        port : 80\n        protocol: TCP\n        targetPort: 80\n      selector:\n        name: nginx\n      sessionAffinity: None\n      type: ClusterIP\n \n- apiVersion: route.openshift.io\/v1\n  kind: Route\n  metadata:\n    labels:\n      app: nginx\n    name: nginx\n  spec:\n    host: ${HOST_NAME}\n    port:\n      targetPort: 80-tcp\n    to:\n      kind: Service\n      name: nginx\n      weight: 100\n \nparameters:\n  - name: HOST_NAME\n    displayName: Host Name\n    required: true  \n  - name: IMAGE_NAME\n    displayName: Image Name\n    required: true\n  - name: REPLICA_COUNT\n    displayName: Replica Count\n    value: \"1\"\n    required: true<\/pre>\n\n\n\n<p><strong>3. \u8fdb\u5165\u8fd0\u884c\u7684\u5bb9\u5668<\/strong><\/p>\n\n\n\n<p>\u53c2\u8003: <a href=\"https:\/\/docs.okd.io\/latest\/dev_guide\/ssh_environment.html\">https:\/\/docs.okd.io\/latest\/dev_guide\/ssh_environment.html<\/a><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># \u67e5\u770bpod\u540d\noc get pods\n \n# \u8fdb\u5165\u5bb9\u5668\noc rsh &lt;pod>\n \n# \u6216\u8005\u76f4\u63a5\u8fdb\u5165dc\noc rsh dc\/nginx<\/pre>\n\n\n\n<p><strong>4. \u5220\u9664\u6240\u6709<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># \u5220\u9664\u6240\u6709\noc delete all -l app=nginx<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5728Openshift\u4e0a\u901a\u8fc7yaml\u90e8\u7f72\u5e94\u7528 1.\u901a\u8fc7\u76f4\u63a5\u6267\u884cyaml \u901a\u8fc7\u5982\u4e0b\u547d\u4ee4\u76f4\u63a5\u6267\u884c oc create [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/10095"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10095"}],"version-history":[{"count":1,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/10095\/revisions"}],"predecessor-version":[{"id":10096,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/10095\/revisions\/10096"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10095"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10095"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10095"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}