首页 体育 教育 财经 社会 娱乐 军事 国内 科技 互联网 房产 国际 女人 汽车 游戏

云端的生存之道,第

2020-05-03

鄙人一部分中,咱们将更新 Kubernetes 布置和 Spring Boot 应用程序以便拜访 Kubernetes 密钥。

Kubernetes 运用 YAML 文件来界说如安在集群中布置和办理应用程序。在上一篇文章中布置 storm-tracker 应用程序时,主动生成了一个 YAML 文件。咱们将需求更新此 YAML 文件,以便咱们的应用程序能够与 PostgreSQL 数据库进行交互。

留意:此刻,如果您没有更新,那么需求转至 storm-tracker 应用程序的根目录。

kubectl get deployments storm-tracker --namespace=default -o yaml deployment.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
 annotations:
 deployment.kubernetes.io/revision: 12 
 kubectl.kubernetes.io/last-applied-configuration: |
 { apiVersion : extensions/v1beta1 , kind : Deployment , metadata :{ annotations :{}, labels :{ run : storm-tracker }, name : storm-tracker , namespace : default , selfLink : /apis/extensions/v1beta1/namespaces/default/deployments/storm-tracker }, spec :{ progressDeadlineSeconds :600, replicas :1, revisionHistoryLimit :10, selector :{ matchLabels :{ run : storm-tracker }}, strategy :{ rollingUpdate :{ maxSurge : 25% , maxUnavailable : 25% }, type : RollingUpdate }, template :{ metadata :{ creationTimestamp :null, labels :{ run : storm-tracker }}, spec :{ containers :[{ args :[ --spring.application.json=$ ], env :[{ name : BINDING , valueFrom :{ secretKeyRef :{ key : binding , name : binding-living-on-the-cloud }}}], image : us.icr.io/openj9-demo/storm-tracker:0.0.2-SNAPSHOT , imagePullPolicy : Always , name : storm-tracker , resources :{}, terminationMessagePath : /dev/termination-log , terminationMessagePolicy : File }], dnsPolicy : ClusterFirst , restartPolicy : Always , schedulerName : default-scheduler , securityContext :{}, terminationGracePeriodSeconds :30}}}}
 creationTimestamp: 2019-08-01T22:48:32Z 
 generation: 25
 labels:
 run: storm-tracker
 name: storm-tracker
 namespace: default
 resourceVersion: 1132314 
 selfLink: /apis/extensions/v1beta1/namespaces/default/deployments/storm-tracker
 uid: 7cb6f3c5-b4ae-11e9-9a9f-461265fcff59
spec:
 progressDeadlineSeconds: 600
 replicas: 1
 revisionHistoryLimit: 10
 selector:
 matchLabels:
 run: storm-tracker
 strategy:
 rollingUpdate:
 maxSurge: 25%
 maxUnavailable: 25%
 type: RollingUpdate
 template:
 metadata:
 creationTimestamp: null
 labels:
 run: storm-tracker
 spec:
 containers:
 image: us.icr.io/openj9-demo/storm-tracker:0.0.1-SNAPSHOT
 imagePullPolicy: Always
 name: storm-tracker
 resources: {}
 terminationMessagePath: /dev/termination-log
 terminationMessagePolicy: File
 dnsPolicy: ClusterFirst
 restartPolicy: Always
 schedulerName: default-scheduler
 securityContext: {}
 terminationGracePeriodSeconds: 30
status:
 availableReplicas: 1
 conditions:
 - lastTransitionTime: 2019-08-09T16:10:37Z 
 lastUpdateTime: 2019-08-09T16:10:37Z 
 message: Deployment has minimum availability.
 reason: MinimumReplicasAvailable
 status: True 
 type: Available
 - lastTransitionTime: 2019-08-09T16:10:32Z 
 lastUpdateTime: 2019-08-09T16:10:37Z 
 message: ReplicaSet storm-tracker-5c99cd9c5f has successfully progressed.
 reason: NewReplicaSetAvailable
 status: True 
 type: Progressing
 observedGeneration: 25
 readyReplicas: 1
 replicas: 1
 updatedReplicas: 1

咱们需求从此 deployment.yaml 中移除很多特定于实例的信息,由于咱们需求的是一个能够在将来复用的模板来奉告 Kubernetes 怎么布置 storm-tracker ,而不是 storm-tracker 当时的快照。

文件,此文件应如下所示:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
 labels:
 run: storm-tracker
 name: storm-tracker
 namespace: default
 selfLink: /apis/extensions/v1beta1/namespaces/default/deployments/storm-tracker
spec:
 progressDeadlineSeconds: 600
 replicas: 1
 revisionHistoryLimit: 10
 selector:
 matchLabels:
 run: storm-tracker
 strategy:
 rollingUpdate:
 maxSurge: 25%
 maxUnavailable: 25%
 type: RollingUpdate
 template:
 metadata:
 creationTimestamp: null
 labels:
 run: storm-tracker
 spec:
 containers:
 - image: us.icr.io/openj9-demo/storm-tracker:0.0.2-SNAPSHOT
 imagePullPolicy: Always
 name: storm-tracker
 resources: {}
 terminationMessagePath: /dev/termination-log
 terminationMessagePolicy: File
 args: [ --spring.application.json=$ ]
 env:
 - name: BINDING
 valueFrom:
 secretKeyRef:
 name: binding-living-on-the-cloud
 key: binding
 dnsPolicy: ClusterFirst
 restartPolicy: Always
 schedulerName: default-scheduler
 securityContext: {}
 terminationGracePeriodSeconds: 30

需求重视以下两个要点方面:

- image: us.icr.io/openj9-demo/storm-tracker:0.0.2-SNAPSHOT

Image 标签已更新为 0.0.2-SNAPSHOT ,因而,当咱们稍后上传新的 docker 镜像时,能够保证运用的是正确的 docker 镜像。此外,经过在每次布置中更改标签版别,咱们能够更轻松地盯梢 Kubernetes 集群在特定时刻点正在运转的代码。

下方的几行:

args: [ --spring.application.json=$ ]
 env:
 - name: BINDING
 valueFrom:
 secretKeyRef:
 name: binding-living-on-the-cloud-db
 key: binding

留意:在 YAML 中,空格具有特定意义。本部分具有正确的格局,因而请保证仿制一切内容。

咱们来逐渐检查 YAML 的这一部分,以便更好地了解所履行的操作:








热门文章

随机推荐

推荐文章