关于Open Shift(OKD) 中应用管理部署的一些笔记
写在前面
- 因为参加考试,会陆续分享一些
OpenShift的笔记 - 博文内容为介绍 openshift 不同的创建应用的方式,包括:
- 基于 IS 创建应用
- 基于镜像创建应用
- 基于源码和 image 创建应用
- 基于源码和 IS 创建应用
- 基于模板创建应用
- 学习环境为 openshift v3 的版本,有些旧
- 这里如果专门学习 openshift ,建议学习 v4 版本
- 理解不足小伙伴帮忙指正
对每个人而言,真正的职责只有一个:找到自我。然后在心中坚守其一生,全心全意,永不停息。所有其它的路都是不完整的,是人的逃避方式,是对大众理想的懦弱回归,是随波逐流,是对内心的恐惧 ——赫尔曼·黑塞《德米安》
应用创建
为了在 OpenShift 中创建新应用程序,您可以使用 oc new-app 命令创建应用,使用 --strategy 标志来指定要使用的构建策略。–strategy 标志可以采用多个值,包括:
- docker:此策略从
Dockerfile构建应用程序。 - source:此策略使用
Source-to-Image (S2I)工具从源代码构建应用程序。 - pipeline:此策略使用
Jenkins管道构建应用程序。
使用了 --strategy=source 标志,这意味着 OpenShift 将使用 S2I 工具从源代码构建应用程序。S2I 是 OpenShift 中的一个工具,它允许开发人员从他们的源代码构建可重现的 Docker 镜像。S2I 通过提供构建和运行容器应用程序的框架简化了构建镜像的过程。
S2I 的工作原理是将您的源代码与基础镜像结合起来创建一个新的镜像,该镜像可以在容器中运行。基础镜像为您的应用程序提供运行时环境,而源代码则提供应用程序代码。S2I 还允许您通过提供可以在构建过程中运行的脚本来自定义构建过程。
要在 OpenShift 中创建 S2I 构建,您可以使用 oc new-app 命令和 --strategy=source 标志。这将创建一个新的构建配置,该配置使用 S2I 构建您的应用程序。然后,您可以将源代码推送到构建配置中,OpenShift 将自动为您构建一个新的镜像。
以下是使用 oc new-app 命令在 OpenShift 中创建 S2I 构建的示例:

基于 IS 创建应用
$ oc new-app --name=mysql -i mysql:latest -e MYSQL_ROOT_PASSWORD=redhat
使用 -i, --image-stream 指定 IS 的镜像位置
要在 OpenShift 上创建一个基于 ImageStream (IS) 的应用,可以按照以下步骤进行操作:
- 创建一个新项目或选择一个现有项目。
- 运行以下命令创建一个 ImageStream:
# 这将在当前项目中创建一个指定名称的新 ImageStream。oc create is <imagestream-name>
- 运行以下命令将镜像导入 ImageStream:
#这将从指定的 URL 导入镜像到 ImageStream 中。oc import-image <imagestream-name> --from=<image-url> --confirm
- 运行以下命令创建一个新应用:
oc new-app -i <imagestream-name>
这将创建一个基于 ImageStream 的新应用程序。
在此过程中,将自动生成多个 API 资源对象,包括:
- ImageStream
- ImageStreamTag
- DeploymentConfig
- Deployment
- Replicationcontroller
- Replicaset
- Service
- Route(路由对象需要手动创建)
当镜像被导入 ImageStream 时,将创建 ImageStream 和 ImageStreamTag 资源。当创建新应用程序时,将创建 DeploymentConfig、Service 和 Route 资源。
这里我们看一个 Demo,创建一个 ImageStream:
┌──[root@vms16.liruilongs.github.io]-[~]
└─$ oc create is myimagestream
imagestream.image.openshift.io/myimagestream created
将镜像导入 ImageStream:
┌──[root@vms16.liruilongs.github.io]-[~]
└─$ oc import-image myimagestream --from=docker.io/nginx --confirm
imagestream.image.openshift.io/myimagestream importedName: myimagestream
Namespace: myproject
Created: 14 seconds ago
Labels: <none>
Annotations: openshift.io/image.dockerRepositoryCheck=2023-04-16T03:21:19Z
Docker Pull Spec: 172.30.1.1:5000/myproject/myimagestream
Image Lookup: local=false
Unique Images: 1
Tags: 1latesttagged from docker.io/nginx* docker.io/nginx@sha256:f2fee5c7194cbbfb9d2711fa5de094c797a42a51aa42b0c8ee8ca31547c872b1Less than a second agoImage Name: myimagestream:latest
Docker Image: docker.io/nginx@sha256:f2fee5c7194cbbfb9d2711fa5de094c797a42a51aa42b0c8ee8ca31547c872b1
Name: sha256:f2fee5c7194cbbfb9d2711fa5de094c797a42a51aa42b0c8ee8ca31547c872b1
Created: Less than a second ago
Annotations: image.openshift.io/dockerLayersOrder=ascending
Image Size: 57.01MB in 6 layers
Layers: 31.42MB sha256:26c5c85e47da3022f1bdb9a112103646c5c29517d757e95426f16e4bd953340525.58MB sha256:4f3256bdf66bf00bcec08043e67a80981428f0e0de12f963eac3c753b14d101d626B sha256:2019c71d56550b97ce01e0b6ef8e971fec705186f2927d2cb109ac3e18edb0ac958B sha256:8c767bdbc9aedd4bbf276c6f28aad18251cceacb768967c5702974ae1eac23cd773B sha256:78e14bb05fd35b58587cd0c5ca2c2eb12b15031633ec30daa21c0ea3d2bb2a151.406kB sha256:75576236abf5959ff23b741ed8c4786e244155b9265db5e6ecda9d8261de529f
Image Created: 3 days ago
Author: <none>
Arch: amd64
Entrypoint: /docker-entrypoint.sh
Command: nginx -g daemon off;
Working Dir: <none>
User: <none>
Exposes Ports: 80/tcp
Docker Labels: maintainer=NGINX Docker Maintainers <docker-maint@nginx.com>
Environment: PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/binNGINX_VERSION=1.23.4NJS_VERSION=0.7.11PKG_RELEASE=1~bullseye
基于 ImageStream 创建一个新应用程序:
┌──[root@vms16.liruilongs.github.io]-[~]
└─$ oc new-app myimagestream
--> Found image 6efc10a (3 days old) in image stream "myproject/myimagestream" under tag "latest" for "myimagestream"* This image will be deployed in deployment config "myimagestream"* Port 80/tcp will be load balanced by service "myimagestream"* Other containers can access this service through the hostname "myimagestream"* WARNING: Image "myproject/myimagestream:latest" runs as the 'root' user which may not be permitted by your cluster administrator--> Creating resources ...deploymentconfig.apps.openshift.io "myimagestream" createdservice "myimagestream" created
--> SuccessApplication is not exposed. You can expose services to the outside world by executing one or more of the commands below:'oc expose svc/myimagestream'Run 'oc status' to view your app.
默认生成的资源,可以看到通过 IS 创建应用会生成
┌──[root@vms16.liruilongs.github.io]-[~]
└─$oc get all
NAME READY STATUS RESTARTS AGE
pod/myimagestream-1-9gfgs 0/1 ContainerCreating 0 23s
pod/myimagestream-1-deploy 1/1 Running 0 24sNAME DESIRED CURRENT READY AGE
replicationcontroller/myimagestream-1 1 1 0 24sNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/myimagestream ClusterIP 172.30.226.178 <none> 80/TCP 24sNAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
deployment.apps/testpod 0 0 0 0 322dNAME DESIRED CURRENT READY AGE
replicaset.apps/testpod-6fd8cb8d9f 0 0 0 322dNAME REVISION DESIRED CURRENT TRIGGERED BY
deploymentconfig.apps.openshift.io/myimagestream 1 1 1 config,image(myimagestream:latest)NAME DOCKER REPO TAGS UPDATED
imagestream.image.openshift.io/myimagestream 172.30.1.1:5000/myproject/myimagestream latest 46 seconds ago
┌──[root@vms16.liruilongs.github.io]-[~]
└─$
基于镜像创建应用
$ oc new-app --docker-image=registry.lab.example.com/openshift/hello-openshift --name=hello
在 OpenShift 上基于 Docker 镜像创建应用,可以使用oc new-app命令。该命令将基于提供的 Docker 镜像创建新的应用程序和构建配置。
在创建过程中,OpenShift 将自动生成多个 API 资源对象,包括
- DeploymentConfig
- ImageStream
- Replicationcontroller
- Service
- router(路由需要自己创建)
这些对象用于管理应用程序及其相关资源。
看一个Demo
[root@master ~]# oc project samples
Now using project "samples" on server "https://master.lab.example.com:443".
在创建的项目下通过镜像构建应用
[root@master ~]# oc new-app --docker-image=registry.lab.example.com/openshift/hello-openshift --name=greeter
--> Found Docker image 7af3297 (4 years old) from registry.lab.example.com for "registry.lab.example.com/openshift/hello-openshift"* An image stream will be created as "greeter:latest" that will track this image* This image will be deployed in deployment config "greeter"* Ports 8080/tcp, 8888/tcp will be load balanced by service "greeter"* Other containers can access this service through the hostname "greeter"--> Creating resources ...imagestream "greeter" createddeploymentconfig "greeter" createdservice "greeter" created
--> SuccessApplication is not exposed. You can expose services to the outside world by executing one or more of the commands below:'oc expose svc/greeter'Run 'oc status' to view your app.
查看创建过程
[root@master ~]# oc status
In project samples on server https://master.lab.example.com:443svc/greeter - 172.30.106.99 ports 8080, 8888dc/greeter deploys istag/greeter:latestdeployment #1 deployed 9 seconds ago - 1 pod2 infos identified, use 'oc status -v' to see details.
[root@master ~]# oc status -v
In project samples on server https://master.lab.example.com:443svc/greeter - 172.30.106.99 ports 8080, 8888dc/greeter deploys istag/greeter:latestdeployment #1 deployed about a minute ago - 1 podInfo:* dc/greeter has no readiness probe to verify pods are ready to accept traffic or ensure deployment is successful.try: oc set probe dc/greeter --readiness ...* dc/greeter has no liveness probe to verify pods are still running.try: oc set probe dc/greeter --liveness ...View details with 'oc describe <resource>/<name>' or list everything with 'oc get all'.
查看通镜像直接构建生成的 API 资源对象
[root@master ~]# oc get all
NAME REVISION DESIRED CURRENT TRIGGERED BY
deploymentconfigs/greeter 1 1 1 config,image(greeter:latest)NAME DOCKER REPO TAGS UPDATED
imagestreams/greeter docker-registry.default.svc:5000/samples/greeter latest About a minute agoNAME READY STATUS RESTARTS AGE
po/greeter-1-gm5qg 1/1 Running 0 1mNAME DESIRED CURRENT READY AGE
rc/greeter-1 1 1 1 1mNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
svc/greeter ClusterIP 172.30.106.99 <none> 8080/TCP,8888/TCP 1m
[root@master ~]#
有些路由可能需要 TSL 等
[root@master ~]# ./gencert.sh greeter.apps.lab.example.com
Generating a private key...
Generating RSA private key, 2048 bit long modulus
............................................................................................+++
....................+++
e is 65537 (0x10001)Generating a CSR...Generating a certificate...
Signature ok
subject=/C=US/ST=NC/L=Raleigh/O=RedHat/OU=RHT/CN=greeter.apps.lab.example.com
Getting Private keyDONE.
创建一个支持 https 的路由
[root@master ~]# oc get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
greeter ClusterIP 172.30.106.99 <none> 8080/TCP,8888/TCP 6m
[root@master ~]# oc create route edge --service=greeter --hostname=greeter.apps.lab.example.com --key=greeter.apps.lab.example.com.key --cert=greeter.apps.lab.example.com.crt
route "greeter" created
[root@master ~]# oc get route
NAME HOST/PORT PATH SERVICES PORT TERMINATION WILDCARD
greeter greeter.apps.lab.example.com greeter 8080-tcp edge None
[root@master ~]# curl greeter.apps.lab.example.com
生成证书文件
[root@master ~]# cat gencert.sh
#!/bin/bashecho "Generating a private key..."
openssl genrsa -out $1.key 2048
echoecho "Generating a CSR..."
openssl req -new -key $1.key -out $1.csr -subj "/C=US/ST=NC/L=Raleigh/O=RedHat/OU=RHT/CN=$1"
echoecho "Generating a certificate..."
openssl x509 -req -days 366 -in $1.csr -signkey $1.key -out $1.crt
echo
echo "DONE."
echo
[root@master ~]#
基于源码和 image 创建应用
[root@master ~]# oc new-app registry.lab.example.com/rhscl/php-70-rhel7~http://services.lab.example.com
/php-helloworld
--> Found Docker image c101534 (5 years old) from registry.lab.example.com for "registry.lab.example.com/rhscl/php-70-rhel7"Apache 2.4 with PHP 7.0-----------------------PHP 7.0 available as docker container is a base platform for building and running various PHP 7.0 applications and frameworks. PHP is an HTML-embedded scripting language. PHP attempts to make it easy for developers to write dynamically generated web pages. PHP also offers built-in database integration for several commercial and non-commercial database management systems, so writing a database-enabled webpage with PHP is fairly simple. The most common use of PHP coding is probably as a replacement for CGI scripts.Tags: builder, php, php70, rh-php70* An image stream will be created as "php-70-rhel7:latest" that will track the source image* A source build using source code from http://services.lab.example.com/php-helloworld will be created* The resulting image will be pushed to image stream "php-helloworld:latest"* Every time "php-70-rhel7:latest" changes a new build will be triggered* This image will be deployed in deployment config "php-helloworld"* Port 8080/tcp will be load balanced by service "php-helloworld"* Other containers can access this service through the hostname "php-helloworld"--> Creating resources ...imagestream "php-70-rhel7" createdimagestream "php-helloworld" createdbuildconfig "php-helloworld" createddeploymentconfig "php-helloworld" createdservice "php-helloworld" created
--> SuccessBuild scheduled, use 'oc logs -f bc/php-helloworld' to track its progress.Application is not exposed. You can expose services to the outside world by executing one or more of the commands below:'oc expose svc/php-helloworld'Run 'oc status' to view your app.
[root@master ~]# oc logs -f bc/php-helloworld
Cloning "http://services.lab.example.com/php-helloworld" ...Commit: 6d61e75647124d02aa761f994532ef29eae46f8e (Establish remote repository)Author: root <root@services.lab.example.com>Date: Thu Aug 9 11:33:29 2018 -0700
---> Installing application source...Pushing image docker-registry.default.svc:5000/rome/php-helloworld:latest ...
Pushed 0/6 layers, 1% complete
Pushed 1/6 layers, 25% complete
Pushed 2/6 layers, 42% complete
Pushed 3/6 layers, 59% complete
Pushed 4/6 layers, 81% complete
Pushed 5/6 layers, 100% complete
Pushed 6/6 layers, 100% complete
Push successful
[root@master ~]#
[root@master ~]# oc get all
NAME REVISION DESIRED CURRENT TRIGGERED BY
deploymentconfigs/php-helloworld 1 1 1 config,image(php-helloworld:latest)NAME TYPE FROM LATEST
buildconfigs/php-helloworld Source Git 1NAME TYPE FROM STATUS STARTED DURATION
builds/php-helloworld-1 Source Git@6d61e75 Complete 2 minutes ago 1m12sNAME DOCKER REPO TAGS UPDATED
imagestreams/php-70-rhel7 docker-registry.default.svc:5000/rome/php-70-rhel7 latest 2 minutes ago
imagestreams/php-helloworld docker-registry.default.svc:5000/rome/php-helloworld latest About a minute agoNAME READY STATUS RESTARTS AGE
po/php-helloworld-1-8hvvn 1/1 Running 0 1m
po/php-helloworld-1-build 0/1 Completed 0 2mNAME DESIRED CURRENT READY AGE
rc/php-helloworld-1 1 1 1 1mNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
svc/php-helloworld ClusterIP 172.30.69.166 <none> 8080/TCP 2m
[root@master ~]#
[root@master ~]# oc expose svc/php-helloworld --hostname=hellophp.apps.lab.example.com
route "php-helloworld" exposed
[root@master ~]# oc get route
NAME HOST/PORT PATH SERVICES PORT TERMINATION WILDCARD
php-helloworld hellophp.apps.lab.example.com php-helloworld 8080-tcp None
[root@master ~]# curl hellophp.apps.lab.example.com
Hello, World! php version is 7.0.10
[root@master ~]#
持续构建
[root@master php-helloworld]# oc start-build php-helloworld
build "php-helloworld-2" started
[root@master php-helloworld]# oc get dc
NAME REVISION DESIRED CURRENT TRIGGERED BY
php-helloworld 2 1 0 config,image(php-helloworld:latest)
[root@master php-helloworld]# oc get build
NAME TYPE FROM STATUS STARTED DURATION
php-helloworld-1 Source Git@6d61e75 Complete 10 minutes ago 1m12s
php-helloworld-2 Source Git@2210bc1 Complete 15 seconds ago 8s
基于源码和 IS 创建应用
$oc new-app --name=hello -i php:7.0 http://registry.lab.example.com/scaling
这里实际上和上面的一样,不在说明
基于模板创建应用
$ oc new-app --template=ruby-helloworld-sample --param=MYSQL_USER=admin $ oc new-app --file=./example/myapp/template.json --param=MYSQL_USER=admi n
以下是使用模板在OpenShift中创建应用的步骤:
- 使用 oc login 命令登录到您的OpenShift集群。
- 使用 oc new-project 命令创建一个新项目。
- 使用 oc get templates -n openshift 命令浏览可用的模板。
- 选择适合您需求的模板,使用 oc new-app 命令创建一个应用。您可以使用 -p 标志指定模板名称和任何参数值。
- 使用 oc get pods 命令监视部署。
当您从模板创建应用时,OpenShift会创建多个资源对象,包括DeploymentConfig、Service、Route和ImageStream。这些对象一起工作,以部署和公开您的应用程序。
DeploymentConfig对象定义了应用程序的部署方式,包括副本数、要使用的容器映像以及任何环境变量或卷挂载。Service对象为您的应用程序提供稳定的IP地址和DNS名称,允许其他服务与其通信。Route对象将您的应用程序公开给外部世界,提供用户可以访问的URL。最后,ImageStream对象跟踪应用程序使用的容器映像,允许您回滚到以前的版本(如果需要)。
一个 模板 yaml 文件 Demo
[root@master ~]# cat gogs-temp.yaml
kind: Template
apiVersion: v1
metadata:annotations:description: The Gogs git server (https://gogs.io/)tags: instant-app,gogs,go,golangname: gogs
objects:
- kind: PersistentVolumeapiVersion: v1metadata:name: gogs-postgres-dataspec:capacity:storage: 2GiaccessModes:- ReadWriteManynfs:path: /exports/gogs-postgres-dataserver: services.lab.example.compersistentVolumeReclaimPolicy: Recycle- kind: PersistentVolumeapiVersion: v1metadata:name: gogs-dataspec:capacity:storage: 1GiaccessModes:- ReadWriteManynfs:path: /exports/gogs-dataserver: services.lab.example.compersistentVolumeReclaimPolicy: Recycle- kind: ServiceAccountapiVersion: v1metadata:creationTimestamp: nulllabels:app: ${APPLICATION_NAME}name: ${APPLICATION_NAME}
- kind: ServiceapiVersion: v1metadata:annotations:description: Exposes the database servername: ${APPLICATION_NAME}-postgresqllabels:app: ${APPLICATION_NAME}spec:ports:- name: postgresqlport: 5432targetPort: 5432selector:name: ${APPLICATION_NAME}-postgresql
- kind: DeploymentConfigapiVersion: v1metadata:annotations:description: Defines how to deploy the databasename: ${APPLICATION_NAME}-postgresqllabels:app: ${APPLICATION_NAME}spec:replicas: 1selector:name: ${APPLICATION_NAME}-postgresqlstrategy:type: Recreatetemplate:metadata:labels:name: ${APPLICATION_NAME}-postgresqlname: ${APPLICATION_NAME}-postgresqlspec:serviceAccountName: ${APPLICATION_NAME}containers:- env:- name: POSTGRESQL_USERvalue: ${DATABASE_USER}- name: POSTGRESQL_PASSWORDvalue: ${DATABASE_PASSWORD}- name: POSTGRESQL_DATABASEvalue: ${DATABASE_NAME}- name: POSTGRESQL_MAX_CONNECTIONSvalue: ${DATABASE_MAX_CONNECTIONS}- name: POSTGRESQL_SHARED_BUFFERSvalue: ${DATABASE_SHARED_BUFFERS}- name: POSTGRESQL_ADMIN_PASSWORDvalue: ${DATABASE_ADMIN_PASSWORD}image: ' 'livenessProbe:initialDelaySeconds: 30tcpSocket:port: 5432timeoutSeconds: 1failureThreshold: 10periodSeconds: 20name: postgresqlports:- containerPort: 5432readinessProbe:exec:command:- /bin/sh- -i- -c- psql -h 127.0.0.1 -U ${POSTGRESQL_USER} -q -d ${POSTGRESQL_DATABASE} -c 'SELECT 1'initialDelaySeconds: 5timeoutSeconds: 1failureThreshold: 10resources:limits:memory: 512MivolumeMounts:- mountPath: /var/lib/pgsql/dataname: gogs-postgres-datavolumes:- name: gogs-postgres-datapersistentVolumeClaim:claimName: gogs-postgres-datatriggers:- imageChangeParams:automatic: truecontainerNames:- postgresqlfrom:kind: ImageStreamTagname: postgresql:9.5namespace: openshifttype: ImageChange- type: ConfigChange
- kind: ServiceapiVersion: v1metadata:annotations:description: The Gogs server's http portservice.alpha.openshift.io/dependencies: '[{"name":"${APPLICATION_NAME}-postgresql","namespace":"","kind":"Service"}]'labels:app: ${APPLICATION_NAME}name: ${APPLICATION_NAME}spec:ports:- name: 3000-tcpport: 3000protocol: TCPtargetPort: 3000selector:app: ${APPLICATION_NAME}deploymentconfig: ${APPLICATION_NAME}sessionAffinity: Nonetype: ClusterIPstatus:loadBalancer: {}
- kind: RouteapiVersion: v1id: ${APPLICATION_NAME}-httpmetadata:annotations:description: Route for application's http service.labels:app: ${APPLICATION_NAME}name: ${APPLICATION_NAME}spec:host: ${HOSTNAME}to:name: ${APPLICATION_NAME}
- kind: DeploymentConfigapiVersion: v1metadata:labels:app: ${APPLICATION_NAME}name: ${APPLICATION_NAME}spec:replicas: 1selector:app: ${APPLICATION_NAME}deploymentconfig: ${APPLICATION_NAME}strategy:resources: {}rollingParams:intervalSeconds: 1maxSurge: 25%maxUnavailable: 25%timeoutSeconds: 600updatePeriodSeconds: 1type: Rollingtemplate:metadata:creationTimestamp: nulllabels:app: ${APPLICATION_NAME}deploymentconfig: ${APPLICATION_NAME}spec:serviceAccountName: ${APPLICATION_NAME}containers:- image: " "imagePullPolicy: Alwaysname: ${APPLICATION_NAME}ports:- containerPort: 3000protocol: TCPresources: {}terminationMessagePath: /dev/termination-logvolumeMounts:- name: gogs-datamountPath: /opt/gogs/data- name: gogs-configmountPath: /etc/gogs/confreadinessProbe:httpGet:path: /port: 3000scheme: HTTPinitialDelaySeconds: 3timeoutSeconds: 1periodSeconds: 20successThreshold: 1failureThreshold: 10livenessProbe:httpGet:path: /port: 3000scheme: HTTPinitialDelaySeconds: 20timeoutSeconds: 1periodSeconds: 10successThreshold: 1failureThreshold: 10dnsPolicy: ClusterFirstrestartPolicy: AlwayssecurityContext: {}terminationGracePeriodSeconds: 30volumes:- name: gogs-datapersistentVolumeClaim:claimName: gogs-data- name: gogs-configconfigMap:name: gogs-configitems:- key: app.inipath: app.initest: falsetriggers:- type: ConfigChange- imageChangeParams:automatic: truecontainerNames:- ${APPLICATION_NAME}from:kind: ImageStreamTagname: ${APPLICATION_NAME}:${GOGS_VERSION}type: ImageChange
- kind: ImageStreamapiVersion: v1metadata:labels:app: ${APPLICATION_NAME}name: ${APPLICATION_NAME}spec:tags:- name: "${GOGS_VERSION}"from:kind: DockerImagename: services.lab.example.com/openshiftdemos/gogs:0.9.97importPolicy: {"insecure":true}annotations:description: The Gogs git server docker imagetags: gogs,go,golangversion: "${GOGS_VERSION}"
- kind: PersistentVolumeClaimapiVersion: v1metadata:name: gogs-datalabels:app: ${APPLICATION_NAME}spec:accessModes:- ReadWriteManyresources:requests:storage: ${GOGS_VOLUME_CAPACITY}
- kind: PersistentVolumeClaimapiVersion: v1metadata:name: gogs-postgres-datalabels:app: ${APPLICATION_NAME}spec:accessModes:- ReadWriteManyresources:requests:storage: ${DB_VOLUME_CAPACITY}
- kind: ConfigMapapiVersion: v1metadata:name: gogs-configlabels:app: ${APPLICATION_NAME}data:app.ini: |RUN_MODE = prodRUN_USER = gogs[database]DB_TYPE = postgresHOST = ${APPLICATION_NAME}-postgresql:5432NAME = ${DATABASE_NAME}USER = ${DATABASE_USER}PASSWD = ${DATABASE_PASSWORD}[repository]ROOT = /opt/gogs/data/repositories[server]ROOT_URL=http://${HOSTNAME}SSH_DOMAIN=${HOSTNAME}[security]INSTALL_LOCK = ${INSTALL_LOCK}[service]ENABLE_CAPTCHA = false[webhook]SKIP_TLS_VERIFY = ${SKIP_TLS_VERIFY}
parameters:
- description: The name for the application.name: APPLICATION_NAMErequired: truevalue: gogs
- description: 'Custom hostname for http service route. Leave blank for default hostname, e.g.: <application-name>-<project>.<default-domain-suffix>'name: HOSTNAMErequired: true
- description: Volume space available for data, e.g. 512Mi, 2Giname: GOGS_VOLUME_CAPACITYrequired: truevalue: 1Gi
- description: Volume space available for postregs data, e.g. 512Mi, 2Giname: DB_VOLUME_CAPACITYrequired: truevalue: 2Gi
- displayName: Database Usernamefrom: gogsvalue: gogsname: DATABASE_USER
- displayName: Database Passwordfrom: '[a-zA-Z0-9]{8}'value: gogsname: DATABASE_PASSWORD
- displayName: Database Namename: DATABASE_NAMEvalue: gogs
- displayName: Database Admin Passwordfrom: '[a-zA-Z0-9]{8}'generate: expressionname: DATABASE_ADMIN_PASSWORD
- displayName: Maximum Database Connectionsname: DATABASE_MAX_CONNECTIONSvalue: "100"
- displayName: Shared Buffer Amountname: DATABASE_SHARED_BUFFERSvalue: 12MB
- name: GOGS_VERSIONdisplayName: Gogs Versiondescription: 'Version of the Gogs container image to be used (check the available version https://hub.docker.com/r/openshiftdemos/gogs/tags)'value: "0.9.97"required: true
- name: INSTALL_LOCKdisplayName: Installation lockdescription: 'If set to true, installation (/install) page will be disabled. Set to false if you want to run the installation wizard via web'value: "true"
- name: SKIP_TLS_VERIFYdisplayName: Skip TLS verification on webhooksdescription: Skip TLS verification on webhooks. Enable with caution!value: "false"
[root@master ~]# gogs-temp.yaml
通过 yaml 文件创建 模板
[root@master ~]# oc apply -f gogs-temp.yaml -n openshift
template "gogs" created
通过模板运行应用
[root@master ~]# oc new-app --template=gogs --param=HOSTNAME=gogs.apps.lab.example.com
--> Deploying template "openshift/gogs" to project dittogogs---------The Gogs git server (https://gogs.io/)* With parameters:* APPLICATION_NAME=gogs* HOSTNAME=gogs.apps.lab.example.com* GOGS_VOLUME_CAPACITY=1Gi* DB_VOLUME_CAPACITY=2Gi* Database Username=gogs* Database Password=gogs* Database Name=gogs* Database Admin Password=iaHaUYMy # generated* Maximum Database Connections=100* Shared Buffer Amount=12MB* Gogs Version=0.9.97* Installation lock=true* Skip TLS verification on webhooks=false--> Creating resources ...persistentvolume "gogs-postgres-data" createdpersistentvolume "gogs-data" createdserviceaccount "gogs" createdservice "gogs-postgresql" createddeploymentconfig "gogs-postgresql" createdservice "gogs" createdroute "gogs" createddeploymentconfig "gogs" createdimagestream "gogs" createdpersistentvolumeclaim "gogs-data" createdpersistentvolumeclaim "gogs-postgres-data" createdconfigmap "gogs-config" created
--> SuccessAccess your application via route 'gogs.apps.lab.example.com'Run 'oc status' to view your app.
[root@master ~]#
查看所有资源
[root@master ~]# oc get all
NAME REVISION DESIRED CURRENT TRIGGERED BY
deploymentconfigs/gogs 0 1 0 config,image(gogs:0.9.97)
deploymentconfigs/gogs-postgresql 1 1 1 config,image(postgresql:9.2)NAME DOCKER REPO TAGS UPDATED
imagestreams/gogs docker-registry.default.svc:5000/ditto/gogs 0.9.97NAME HOST/PORT PATH SERVICES PORT TERMINATION WILDCARD
routes/gogs gogs.apps.lab.example.com gogs <all> NoneNAME READY STATUS RESTARTS AGE
po/gogs-postgresql-1-9rjb2 0/1 Running 0 30s
po/gogs-postgresql-1-deploy 1/1 Running 0 33sNAME DESIRED CURRENT READY AGE
rc/gogs-postgresql-1 1 1 0 33sNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
svc/gogs ClusterIP 172.30.4.106 <none> 3000/TCP 33s
svc/gogs-postgresql ClusterIP 172.30.127.172 <none> 5432/TCP 34s
[root@master ~]#
博文部分内容参考
© 文中涉及参考链接内容版权归原作者所有,如有侵权请告知,这是一个开源项目,如果你认可它,不要吝啬星星哦 😃
《OKD 3.9 DO280 Red Hat OpenShift Administration I》
《开源容器云OpenShift:构建基于Kubernetes的企业应用云平台》
https://docs.okd.io/latest/welcome/index.html
© 2018-2023 liruilonger@gmail.com, All rights reserved. 保持署名-非商用-相同方式共享(CC BY-NC-SA 4.0)
相关文章:
关于Open Shift(OKD) 中应用管理部署的一些笔记
写在前面 因为参加考试,会陆续分享一些 OpenShift 的笔记博文内容为介绍 openshift 不同的创建应用的方式,包括: 基于 IS 创建应用基于镜像创建应用基于源码和 image 创建应用基于源码和 IS 创建应用基于模板创建应用 学习环境为 openshift v…...
【linux】对于权限的理解
权限 Linux权限的概念用户之间的切换 Linux权限管理文件权限操作文件的人Linux文件默认权限的设置权限掩码 所属组/其他删除拥有者创建的文件文件拥有者、所属组的修改修改文件拥有者修改文件所属组一次性修改拥有者和所属组 目录的执行权限 Linux权限的概念 首先,…...
测试人必备技能:如何进行WebSocket接口测试?
目录 前言 WebSocket介绍 HTTP与WebSocket的区别 二者关系 WebSocket测试方法 使用Postman 使用Jmeter 使用Python 结语 前言 随着Web应用的日益普及,WebSocket作为一种全双工通信协议,在移动端、游戏、视频会议等方面得到广泛应用。 而对于需…...
【Android FrameWork (三)】- SystemServer
文章目录 知识回顾启动第一个流程initZygote的流程 前言源码分析1.system_server2.SystemServer.main3,startBootstrapServices4,startService 拓展知识LoadApkcontext 对于Android context 大家是怎么理解的?LocalServices.java: addServece方法中 ArrayMap和HashM…...
Docker容器部署及基本使用
文章目录 一、环境初始化配置二、安装Docker三、优化配置四、基础命令 一、环境初始化配置 1、关闭防火墙 systemctl stop firewalld systemctl disable firewalldsetenforce 0sed -i s/SELINUXenforcing/SELINUXdisabled/g /etc/selinux/config sed -i s/SELINUXenforcing/S…...
【机智云物联网低功耗转接板】+模拟MCU快速上手
GE211是机智云自研的定制化转接板,使用 ESP32-C3-WROOM-02 通讯模块,适用于白色智能家电等设备应用。 转接板已经烧录了机智云连云的最新GAgent固件,所以不需要烧写任何软件就可以快速上手使用。 GE211板卡带有一个串口,一般是把这…...
ai免费写作在线平台-ai免费伪原创文章生成器软件
ai伪原创能检测出来吗 人工智能技术可以检测伪原创,但是不是所有的伪原创都可以被检测出来。 现在有许多自然语言处理(NLP)算法和技术可以用来检测伪原创内容,例如文本相似度比较算法,语气分析算法等。这些算法可以检…...
Web自动化测试简介及web自动化测试实战交教程
一、认识web自动化测试 1.什么是自动化测试? 自动化测试的概念: 软件自动化测试就是通过测试工具或者其他手段,按照测试人员的预定计划对软件产品进行自动化测试,他是软件测试的一个重要组成部分,能够完成许多手工测试无法完成或…...
基于单片机的家庭应急电源设计
基于单片机的家庭应急电源 摘 要 本设计基于STC89C52单片机设计得应急电源,以应急电源为研究对象,单片机设计为控制集成IC,ADC为模数转换控制模块,无源蜂鸣器作为报警电路。系统分为单片机设计最小系统,AD转换控制模…...
线程七大状态
线程生命周期(七大状态) 新建状态(New):当Java线程被创建时,它处于新建状态。此时,线程对象已被创建,但尚未启动。在这个状态下,线程并没有开始执行任何代码,…...
Linux第一章
文章目录 前言一、操作系统概述二、Linux初识1.Linux系统的诞生2.Linux系统内核3.Linux发行版 三、虚拟机介绍四、安装vmware workStation1.VMware WorStation软件2.安装 五、vm安装linux六、远程连接Linux系统1.图形化、命令行2.为什么使用命令行操作linux3.使用FinalShell软件…...
Microsoft Defender for Identity部署方案
目录 前言 一、重要组件 二、部署步骤 1、准备 Azure 订阅 2、配置 Microsoft Defender for Identity 门户...
超越YOLOv8,飞桨推出精度最高的实时检测器RT-DETR!
众所周知,实时目标检测( Real-Time Object Detection )一直由 YOLO 系列模型主导。 飞桨在去年 3 月份推出了高精度通用目标检测模型 PP-YOLOE ,同年在 PP-YOLOE 的基础上提出了 PP-YOLOE 。后者在训练收敛速度、下游任务泛化能力以及高性能部署能力…...
基于Docker安装Redis【保姆级教程、内含图解】
Redis官网:Redis Redis中文官网:CRUG网站 两者选其一即可,建议使用 Redis官网:Redis 学习任何框架和技术,一定要参考相应的官网学习,一定要参考官网学习!!! 目录 一、拉取…...
电子表格软件与一站式BI的区别
看完本节内容,相信您能够了解到电子表格软件(代号电子表格软件)与「一站式 BI」的主要区别。所谓一站式BI在官网上的名称就是Smartbi V10.5,代号就是Smartbi一直在使用insight。 这两个产品都属于商业智能BI软件的品类࿰…...
SpringCache
一、介绍 Spring Cache是一个框架,实现了基于注解的缓存功能,只需要简单地加一个注解,就能实现缓存功能,大大简化我们在业务中操作缓存的代码。 Spring Cache只是提供了一层抽象,底层可以切换不同的cache实现。具体就…...
Android Framework—Service
介绍 Service是一种可以在后台执行长时间运行操作而不提供界面的应用组件。服务可以由其他应用组件启动,而且即使用户切换到其他应用,服务仍将在后台继续运行。此外,组件可以通过绑定到服务与之进行交互,甚至是执行进程之间的通信…...
leetcode (重排数组使得)连续子数组的权值和最小
题目描述:请重新排列某个仅包含2和3的数组,使得数组的所有连续子数组权值之和最小数组的权值定义为,数组中所有元素之积的因子个数,例如:rank([2,3])4 x p 1 c 1 p 2 c 2 p 3 c 3 ⋅ ⋅ ⋅ p k c k r a n k ( c 1 1 ) ( c …...
JSP计算机等级考试查询系统(源代码+论文+答辩PPT)
第一章 引言 计算机等级考试查询系统是有其开发的必要性的,它的应用将大大节省了学校的人力资源,从而从人工劳动中解脱出来。我们这次开发的软件系统一共包括了三个部分:等级考试的报名系统、查询系统和管理系统。其中管理系统是另外两部分…...
python 基础系列篇:七、以函数方式编写一个数字华容道
python 基础系列篇:七、以函数方式编写一个数字华容道 数字华容道游戏分析开始编写完整代码代码解说定义方法的规律 小结 数字华容道 嗯,就是一个简单的益智游戏,把数字按照特定规律排列,并比矩阵少一个格,用来进行移…...
SkyWalking 10.2.0 SWCK 配置过程
SkyWalking 10.2.0 & SWCK 配置过程 skywalking oap-server & ui 使用Docker安装在K8S集群以外,K8S集群中的微服务使用initContainer按命名空间将skywalking-java-agent注入到业务容器中。 SWCK有整套的解决方案,全安装在K8S群集中。 具体可参…...
智慧医疗能源事业线深度画像分析(上)
引言 医疗行业作为现代社会的关键基础设施,其能源消耗与环境影响正日益受到关注。随着全球"双碳"目标的推进和可持续发展理念的深入,智慧医疗能源事业线应运而生,致力于通过创新技术与管理方案,重构医疗领域的能源使用模式。这一事业线融合了能源管理、可持续发…...
树莓派超全系列教程文档--(61)树莓派摄像头高级使用方法
树莓派摄像头高级使用方法 配置通过调谐文件来调整相机行为 使用多个摄像头安装 libcam 和 rpicam-apps依赖关系开发包 文章来源: http://raspberry.dns8844.cn/documentation 原文网址 配置 大多数用例自动工作,无需更改相机配置。但是,一…...
K8S认证|CKS题库+答案| 11. AppArmor
目录 11. AppArmor 免费获取并激活 CKA_v1.31_模拟系统 题目 开始操作: 1)、切换集群 2)、切换节点 3)、切换到 apparmor 的目录 4)、执行 apparmor 策略模块 5)、修改 pod 文件 6)、…...
.Net框架,除了EF还有很多很多......
文章目录 1. 引言2. Dapper2.1 概述与设计原理2.2 核心功能与代码示例基本查询多映射查询存储过程调用 2.3 性能优化原理2.4 适用场景 3. NHibernate3.1 概述与架构设计3.2 映射配置示例Fluent映射XML映射 3.3 查询示例HQL查询Criteria APILINQ提供程序 3.4 高级特性3.5 适用场…...
【第二十一章 SDIO接口(SDIO)】
第二十一章 SDIO接口 目录 第二十一章 SDIO接口(SDIO) 1 SDIO 主要功能 2 SDIO 总线拓扑 3 SDIO 功能描述 3.1 SDIO 适配器 3.2 SDIOAHB 接口 4 卡功能描述 4.1 卡识别模式 4.2 卡复位 4.3 操作电压范围确认 4.4 卡识别过程 4.5 写数据块 4.6 读数据块 4.7 数据流…...
相机Camera日志分析之三十一:高通Camx HAL十种流程基础分析关键字汇总(后续持续更新中)
【关注我,后续持续新增专题博文,谢谢!!!】 上一篇我们讲了:有对最普通的场景进行各个日志注释讲解,但相机场景太多,日志差异也巨大。后面将展示各种场景下的日志。 通过notepad++打开场景下的日志,通过下列分类关键字搜索,即可清晰的分析不同场景的相机运行流程差异…...
C# SqlSugar:依赖注入与仓储模式实践
C# SqlSugar:依赖注入与仓储模式实践 在 C# 的应用开发中,数据库操作是必不可少的环节。为了让数据访问层更加简洁、高效且易于维护,许多开发者会选择成熟的 ORM(对象关系映射)框架,SqlSugar 就是其中备受…...
OPENCV形态学基础之二腐蚀
一.腐蚀的原理 (图1) 数学表达式:dst(x,y) erode(src(x,y)) min(x,y)src(xx,yy) 腐蚀也是图像形态学的基本功能之一,腐蚀跟膨胀属于反向操作,膨胀是把图像图像变大,而腐蚀就是把图像变小。腐蚀后的图像变小变暗淡。 腐蚀…...
sipsak:SIP瑞士军刀!全参数详细教程!Kali Linux教程!
简介 sipsak 是一个面向会话初始协议 (SIP) 应用程序开发人员和管理员的小型命令行工具。它可以用于对 SIP 应用程序和设备进行一些简单的测试。 sipsak 是一款 SIP 压力和诊断实用程序。它通过 sip-uri 向服务器发送 SIP 请求,并检查收到的响应。它以以下模式之一…...
