在Openshift上通过yaml部署应用
1.通过直接执行yaml
通过如下命令直接执行
nginx.yml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
| apiVersion: v1 items: - apiVersion: apps.openshift.io/v1 kind: DeploymentConfig metadata: labels: app: nginx name: nginx namespace: test spec: replicas: 1 resources: limits: cpu: 300m memory: 1024Mi requests: cpu: 100m memory: 200Mi selector: name: nginx strategy: type: Rolling template: metadata: labels: app: nginx name: nginx deploymentconfig: nginx spec: containers: - capabilities: {} env: - name: TZ value: Asia/Shanghai - name: LANG value: en_US.UTF-8 image: nginx:1.16 imagePullPolicy: IfNotPresent ports: - containerPort: 80 protocol: TCP
livenessProbe: failureThreshold: 2 httpGet: path: / port: 80 initialDelaySeconds: 60 periodSeconds: 60 timeoutSeconds: 5 name: nginx readinessProbe: httpGet: path: / port: 80 initialDelaySeconds: 3 timeoutSeconds: 5 resources: limits: cpu: 300m memory: 1024Mi requests: cpu: 100m memory: 200Mi securityContext: capabilities: {} terminationMessagePath: /dev/termination-log dnsPolicy: ClusterFirst restartPolicy: Always triggers: - type: ConfigChange - apiVersion: v1 kind: Service metadata: labels: app: nginx name: nginx spec: ports: - name: http port: 80 protocol: TCP targetPort: 80 selector: name: nginx sessionAffinity: None type: ClusterIP - apiVersion: route.openshift.io/v1 kind: Route metadata: labels: app: nginx name: nginx spec: host: xinchen.app.com to: kind: Service name: nginx kind: List metadata: {}
|
2. 通过创建template
参考文档: https://docs.okd.io/latest/dev_guide/templates.html#writing-templates
相关指令
1 2 3 4 5 6 7 8 9 10 11 12 13
|
oc create -f <filename> -n <project>
oc process -f nginx-template -p IMAGE_NAME=nginx:1.6 -p REPLICA_COUNT=1
oc edit template <templateName>
oc get -o yaml --export all > <yaml_filename>
|
nginx-template.yml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
| kind: Template apiVersion: v1 metadata: name: nginx-template objects: - kind: DeploymentConfig apiVersion: v1 metadata: name: nginx namespace: xinchen labels: app: nginx spec: replicas: ${REPLICA_COUNT} selector: name: nginx resources: limits: cpu: 300m memory: 1024Mi requests: cpu: 100m memory: 200Mi strategy: type: Rolling template: metadata: labels: app: nginx name: nginx deploymentconfig: nginx spec: containers: - capabilities: {} env: - name: TZ value: Asia/Shanghai - name: LANG value: en_US.UTF-8
image: ${IMAGE_NAME} imagePullPolicy: IfNotPresent
ports: - containerPort: 80 protocol: TCP livenessProbe: failureThreshold: 2 httpGet: path: / port: 80 initialDelaySeconds: 60 periodSeconds: 60 timeoutSeconds: 5 name: nginx readinessProbe: httpGet: path: / port: 80 initialDelaySeconds: 3 timeoutSeconds: 5 resources: limits: cpu: 300m memory: 1024Mi requests: cpu: 100m memory: 200Mi
securityContext: capabilities: {} terminationMessagePath: /dev/termination-log dnsPolicy: ClusterFirst restartPolicy: Always triggers: - type: ConfigChange
- kind: Service apiVersion: v1 metadata: name: nginx labels: app: nginx spec: ports: - name: 80-tcp port : 80 protocol: TCP targetPort: 80 selector: name: nginx sessionAffinity: None type: ClusterIP
- apiVersion: route.openshift.io/v1 kind: Route metadata: labels: app: nginx name: nginx spec: host: ${HOST_NAME} port: targetPort: 80-tcp to: kind: Service name: nginx weight: 100
parameters: - name: HOST_NAME displayName: Host Name required: true - name: IMAGE_NAME displayName: Image Name required: true - name: REPLICA_COUNT displayName: Replica Count value: "1" required: true
|
3. 进入运行的容器
参考: https://docs.okd.io/latest/dev_guide/ssh_environment.html
1 2 3 4 5 6 7 8 9
|
oc get pods
oc rsh <pod>
oc rsh dc/nginx
|
4. 删除所有
1 2
| oc delete all -l app=nginx
|