* docker.io/nginx@sha256:f2fee5c7194cbbfb9d2711fa5de094c797a42a51aa42b0c8ee8ca31547c872b1 Less than a second ago
Image 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:26c5c85e47da3022f1bdb9a112103646c5c29517d757e95426f16e4bd9533405 25.58MB sha256:4f3256bdf66bf00bcec08043e67a80981428f0e0de12f963eac3c753b14d101d 626B sha256:2019c71d56550b97ce01e0b6ef8e971fec705186f2927d2cb109ac3e18edb0ac 958B sha256:8c767bdbc9aedd4bbf276c6f28aad18251cceacb768967c5702974ae1eac23cd 773B sha256:78e14bb05fd35b58587cd0c5ca2c2eb12b15031633ec30daa21c0ea3d2bb2a15 1.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:/bin NGINX_VERSION=1.23.4 NJS_VERSION=0.7.11 PKG_RELEASE=1~bullseye
基于 ImageStream 创建一个新应用程序:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
┌──[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" created service "myimagestream" created --> Success Application 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.
┌──[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 24s
NAME DESIRED CURRENT READY AGE replicationcontroller/myimagestream-1 1 1 0 24s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/myimagestream ClusterIP 172.30.226.178 <none> 80/TCP 24s
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE deployment.apps/testpod 0 0 0 0 322d
NAME DESIRED CURRENT READY AGE replicaset.apps/testpod-6fd8cb8d9f 0 0 0 322d
NAME 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]-[~] └─$
[root@master ~]# oc project samples Now using project "samples" on server "https://master.lab.example.com:443".
在创建的项目下通过镜像构建应用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
[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" created deploymentconfig "greeter" created service "greeter" created --> Success Application 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:443
svc/greeter - 172.30.106.99 ports 8080, 8888 dc/greeter deploys istag/greeter:latest deployment #1 deployed 9 seconds ago - 1 pod
2 infos identified, use 'oc status -v' to see details. [root@master ~]# oc status -v In project samples on server https://master.lab.example.com:443
svc/greeter - 172.30.106.99 ports 8080, 8888 dc/greeter deploys istag/greeter:latest deployment #1 deployed about a minute ago - 1 pod
Info: * 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 资源对象
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
[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 ago
NAME READY STATUS RESTARTS AGE po/greeter-1-gm5qg 1/1 Running 0 1m
NAME DESIRED CURRENT READY AGE rc/greeter-1 1 1 1 1m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE svc/greeter ClusterIP 172.30.106.99 <none> 8080/TCP,8888/TCP 1m [root@master ~]#
有些路由可能需要 TSL 等
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
[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 key
DONE.
创建一个支持 https 的路由
1 2 3 4 5 6 7 8 9
[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
生成证书文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
[root@master ~]# cat gencert.sh #!/bin/bash
echo"Generating a private key..." openssl genrsa -out $1.key 2048 echo
[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" created imagestream "php-helloworld" created buildconfig "php-helloworld" created deploymentconfig "php-helloworld" created service "php-helloworld" created --> Success Build 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...
[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 1
NAME TYPE FROM STATUS STARTED DURATION builds/php-helloworld-1 Source Git@6d61e75 Complete 2 minutes ago 1m12s
NAME 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 ago
NAME READY STATUS RESTARTS AGE po/php-helloworld-1-8hvvn 1/1 Running 0 1m po/php-helloworld-1-build 0/1 Completed 0 2m
NAME DESIRED CURRENT READY AGE rc/php-helloworld-1 1 1 1 1m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE svc/php-helloworld ClusterIP 172.30.69.166 <none> 8080/TCP 2m [root@master ~]#
1 2 3 4 5 6 7 8
[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 ~]#
持续构建
1 2 3 4 5 6 7 8 9
[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
[webhook] SKIP_TLS_VERIFY=${SKIP_TLS_VERIFY} parameters: -description:Thenamefortheapplication. name:APPLICATION_NAME required:true value:gogs -description:'Custom hostname for http service route. Leave blank for default hostname, e.g.: <application-name>-<project>.<default-domain-suffix>' name:HOSTNAME required:true -description:Volumespaceavailablefordata,e.g.512Mi,2Gi name:GOGS_VOLUME_CAPACITY required:true value:1Gi -description:Volumespaceavailableforpostregsdata,e.g.512Mi,2Gi name:DB_VOLUME_CAPACITY required:true value:2Gi -displayName:DatabaseUsername from:gogs value:gogs name:DATABASE_USER -displayName:DatabasePassword from:'[a-zA-Z0-9]{8}' value:gogs name:DATABASE_PASSWORD -displayName:DatabaseName name:DATABASE_NAME value:gogs -displayName:DatabaseAdminPassword from:'[a-zA-Z0-9]{8}' generate:expression name:DATABASE_ADMIN_PASSWORD -displayName:MaximumDatabaseConnections name:DATABASE_MAX_CONNECTIONS value:"100" -displayName:SharedBufferAmount name:DATABASE_SHARED_BUFFERS value:12MB -name:GOGS_VERSION displayName:GogsVersion description:'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_LOCK displayName:Installationlock description:'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_VERIFY displayName:SkipTLSverificationonwebhooks description:SkipTLSverificationonwebhooks.Enablewithcaution! value:"false" [root@master~]# gogs-temp.yaml
--> Creating resources ... persistentvolume "gogs-postgres-data" created persistentvolume "gogs-data" created serviceaccount "gogs" created service "gogs-postgresql" created deploymentconfig "gogs-postgresql" created service "gogs" created route "gogs" created deploymentconfig "gogs" created imagestream "gogs" created persistentvolumeclaim "gogs-data" created persistentvolumeclaim "gogs-postgres-data" created configmap "gogs-config" created --> Success Access 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.97
NAME HOST/PORT PATH SERVICES PORT TERMINATION WILDCARD routes/gogs gogs.apps.lab.example.com gogs <all> None
NAME READY STATUS RESTARTS AGE po/gogs-postgresql-1-9rjb2 0/1 Running 0 30s po/gogs-postgresql-1-deploy 1/1 Running 0 33s
NAME DESIRED CURRENT READY AGE rc/gogs-postgresql-1 1 1 0 33s
NAME 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 ~]#