OpenShift笔记(二):OpenShift的命令行工具
📅 2017-11-16 | 🖱️
oc命令 #
我们已经使用二进制包手工安装了OpenShift,并且使用OpenShift的Web控制台创建了一个项目。 实际上OpenShift还提供了一系列命令行工具,oc命令就是其中的一个,下面我们一起熟悉一下这个命令。
查看OpenShift集群版本信息:
1oc version
2oc v3.6.1+008f2d5
3kubernetes v1.6.1+5115d708d7
4features: Basic-Auth GSSAPI Kerberos SPNEGO
5
6Server https://192.168.61.134:8443
7openshift v3.6.1+008f2d5
8kubernetes v1.6.1+5115d708d7
使用oc命令前需要先登录:
1oc login -u dev https://192.168.61.134:8443
2Authentication required for https://192.168.61.134:8443 (openshift)
3Username: dev
4Password:
5Login successful.
6
7You have one project on this server: "prj1"
8
9Using project "prj1".
使用oc命令创建一个新项目prj2:
1oc new-project prj2
2Now using project "prj2" on server "https://192.168.61.134:8443".
3
4You can add applications to this project with the 'new-app' command. For example, try:
5
6 oc new-app centos/ruby-22-centos7~https://github.com/openshift/ruby-ex.git
7
8to build a new example application in Ruby.
切换到prj2项目:
1oc project prj2
2Already on project "prj2" on server "https://192.168.61.134:8443".
往项目中添加应用:
1oc new-app openshift/hello-openshift
2--> Found Docker image 3533a24 (2 days old) from Docker Hub for "openshift/hello-openshift"
3
4 * An image stream will be created as "hello-openshift:latest" that will track this image
5 * This image will be deployed in deployment config "hello-openshift"
6 * Ports 8080/tcp, 8888/tcp will be load balanced by service "hello-openshift"
7 * Other containers can access this service through the hostname "hello-openshift"
8 * WARNING: Image "openshift/hello-openshift" runs as the 'root' user which may not be permitted by your cluster administrator
9
10--> Creating resources ...
11 imagestream "hello-openshift" created
12 deploymentconfig "hello-openshift" created
13 service "hello-openshift" created
14--> Success
15 WARNING: No Docker registry has been configured with the server. Automatic builds and deployments may not function.
16 Run 'oc status' to view your app.
可以看到上面的命令输出实际上应该是在Kubernetes上创建了hello-openshift的Deployment和Service。 在添加过程中会下载Docker镜像,如果网络比较慢,可以提前pull好:
1docker pull openshift/origin-pod:v3.6.1
2docker pull openshift/origin-deployer:v3.6.1
查看部署的应用:
1oc status
2In project prj2 on server https://192.168.61.134:8443
3
4svc/hello-openshift - 172.30.158.204 ports 8080, 8888
5 dc/hello-openshift deploys istag/hello-openshift:latest
6 deployment #1 deployed 10 minutes ago - 1 pod
7
8View details with 'oc describe <resource>/<name>' or list everything with 'oc get all'.
如果对Kubernetes比较熟悉的话,下面的oc命令应该不用解释了:
1oc get pod
2NAME READY STATUS RESTARTS AGE
3hello-openshift-1-x6m7b 1/1 Running 0 1m
4
5oc get svc
6NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
7hello-openshift 172.30.158.204 <none> 8080/TCP,8888/TCP 11m
退出登录:
1oc logout
2Logged "dev" out on "https://192.168.61.134:8443"