OpenShift 3上的Couchbase

OpenShift是Red Hat的开源PaaS平台。 OpenShift 3提供了使用Docker和Kubernetes运行应用程序的整体体验。 以经典的Red Hat方式,所有工作都在OpenShift Origin的开源中完成。 这也推动了OpenShift OnlineOpenShift Enterprise的下一个主要版本。

使用Docker和Kubernetes进行容器编排的OpenShift 3使得带Docker映像的所有产品的运行变得非常简单。 该博客介绍了如何在OpenShift 3上开始使用Couchbase

OpenShift 3入门图1_50401

  • 从以下位置下载最新的Vagrant框 (撰写本文时为1.1)和Vagrantfileopenshift.org/vm/ 。 将它们复制到同一目录中。Vagrantfile配置为2GB内存,如果需要运行更多容器,可以对其进行更新。 OpenShift Master,Node,Docker Registry和其他组件在VM内运行。本博客使用Vagrant 1.7.4和VirtualBox 5.0.10r104061编写。
  • 添加游民箱:
    vagrant box add --name openshift3 openshift-bootstrap-1.1.box 
    ==> box: Box file was not detected as metadata. Adding it directly...
    ==> box: Adding box 'openshift3' (v0) for provider: 
        box: Unpacking necessary files from: file:///Users/arungupta/tools/openshiftv3/1.1/openshift-bootstrap-1.1.box
    ==> box: Successfully added box 'openshift3' (v0) for 'virtualbox'!
  • 启动虚拟机:
    vagrant up
    Bringing machine 'default' up with 'virtualbox' provider...
    ==> default: Setting the name of the VM: openshift3
    ==> default: Clearing any previously set network interfaces...
    ==> default: Preparing network interfaces based on configuration...
        default: Adapter 1: nat
    ==> default: Forwarding ports...
        default: 80 => 1080 (adapter 1)
        default: 443 => 1443 (adapter 1)
        default: 5000 => 5000 (adapter 1)
        default: 8080 => 8080 (adapter 1)
        default: 8443 => 8443 (adapter 1)
        default: 22 => 2222 (adapter 1)
    ==> default: Running 'pre-boot' VM customizations...
    ==> default: Booting VM...
    ==> default: Waiting for machine to boot. This may take a few minutes...
        default: SSH address: 127.0.0.1:2222
        default: SSH username: vagrant
        default: SSH auth method: private key
        default: Warning: Connection timeout. Retrying...
    ==> default: Machine booted and ready!
    ==> default: Checking for guest additions in VM...
        default: The guest additions on this VM do not match the installed version of
        default: VirtualBox! In most cases this is fine, but in rare cases it can
        default: prevent things such as shared folders from working properly. If you see
        default: shared folder errors, please make sure the guest additions within the
        default: virtual machine match the version of VirtualBox you have installed on
        default: your host and reload your VM.
        default: 
        default: Guest Additions Version: 4.3.20
        default: VirtualBox Version: 5.0

下载并配置OpenShift 3客户端

  • openshift.org/vm/下载Mac 64位客户端工具gem install rhc仅适用于v2),并将其压缩到目录中。 清单看起来像:
    tar xzvf ~/Downloads/openshift-origin-v1.1-ac7a99a-darwin-amd64.tar.gz 
    x ./
    x ./oadm
    x ./kube-scheduler
    x ./kubelet
    x ./kube-apiserver
    x ./openshift
    x ./kube-controller-manager
    x ./kube-proxy
    x ./oc
    x ./kubectl
  • 验证客户端版本:
    ./oc version
    oc v1.1
    kubernetes v1.1.0-origin-1107-g4c8e6f4
  • 删除~/.kube/config或重命名为其他名称。
  • 登录到OpenShift:
    ./oc login
    Server [https://localhost:8443]: 
    The server uses a certificate signed by an unknown authority.
    You can bypass the certificate check, but any data you send to the server could be intercepted by others.
    Use insecure connections? (y/n): y
    
    Authentication required for https://localhost:8443 (openshift)
    Username: admin
    Password: 
    Login successful.
    
    You have access to the following projects and can switch between them with 'oc project <projectname>':
    
      * default (current)
      * openshift
      * turbo
    
    Using project "default".
    Welcome! See 'oc help' to get started.

在OpenShift 3中创建Couchbase应用程序图2_50401

  • 创建一个新的Couchbase实例:
    ./oc new-app arungupta/couchbase
    --> Found Docker image 9131c5a (2 days old) from Docker Hub for "arungupta/couchbase"
        * An image stream will be created as "couchbase:latest" that will track this image
        * This image will be deployed in deployment config "couchbase"
        * Ports 11207/tcp, 11210/tcp, 11211/tcp, 18091/tcp, 18092/tcp, 8091/tcp, 8092/tcp, 8093/tcp will be load balanced by service "couchbase"
    --> Creating resources with label app=couchbase ...
        ImageStream "couchbase" created
        DeploymentConfig "couchbase" created
        Service "couchbase" created
    --> Success
        Run 'oc status' to view your app.

    arungupta/couchbase是因为它使用Couchbase REST API通过以下方式预配置Couchbase服务器:

    • 内存和索引配额

    该样本存储桶稍后将用于查询数据。

  • 检查部署状态:
    ./oc status
    In project default on server https://localhost:8443
    
    svc/couchbase - 172.30.84.134 ports 8091, 8092, 8093, 11207, 11210, 11211, 18091, 18092
      dc/couchbase deploys imagestreamtag/couchbase:latest 
        #1 deployed about a minute ago - 1 pod
    
    svc/docker-registry - 172.30.236.154:5000
      dc/docker-registry deploys docker.io/openshift/origin-docker-registry:v1.1 
        #1 deployed 4 weeks ago - 1 pod
    
    svc/kubernetes - 172.30.0.1 ports 443, 53, 53
    
    svc/router - 172.30.233.69:80
      dc/router deploys docker.io/openshift/origin-haproxy-router:v1.1 
        #1 deployed 4 weeks ago - 1 pod
    
    Warnings:
      * container "registry" in pod/docker-registry-1-imxqp has restarted 5 times
      * container "openshift-registry-proxy-1" in pod/openshift-registry-proxy has restarted 3 times
      * container "router" in pod/router-1-5grim has restarted 5 times
    
    To see more, use 'oc describe <resource>/<name>'.
    You can use 'oc get all' to see a list of other objects.
  • 查找豆荚列表:
    client > ./oc get po
    NAME                       READY     STATUS    RESTARTS   AGE
    couchbase-1-5zhju          1/1       Running   0          1d
    docker-registry-1-imxqp    1/1       Running   5          32d
    openshift-registry-proxy   1/1       Running   3          32d
    router-1-5grim             1/1       Running   5          32d
  • 获取有关Couchbase窗格的更多详细信息:
    ./oc describe po couchbase-1-5zhju
    Name:				couchbase-1-5zhju
    Namespace:			default
    Image(s):			arungupta/couchbase@sha256:9131c5a283d79e11b6556c94b0b0f8ceba7daf5ba5982bac850100099019959f
    Node:				localhost.localdomain/10.0.2.15
    Start Time:			Sat, 19 Dec 2015 08:19:31 -0800
    Labels:				app=couchbase,deployment=couchbase-1,deploymentconfig=couchbase
    Status:				Running
    Reason:				
    Message:			
    IP:				172.17.0.7
    Replication Controllers:	couchbase-1 (1/1 replicas created)
    Containers:
      couchbase:
        Container ID:	docker://bd51f655c2a54f92f4634b84f455ca91642a88b925be39126f07df43ce883a33
        Image:		arungupta/couchbase@sha256:9131c5a283d79e11b6556c94b0b0f8ceba7daf5ba5982bac850100099019959f
        Image ID:		docker://c9d204bb75427500ef94263f8f53e8b78f2e56efd37543e620aebb1bc1bd7de1
        QoS Tier:
          cpu:		BestEffort
          memory:		BestEffort
        State:		Running
          Started:		Sat, 19 Dec 2015 08:20:21 -0800
        Ready:		True
        Restart Count:	0
        Environment Variables:
    Conditions:
      Type		Status
      Ready 	True 
    Volumes:
      couchbase-volume-1:
        Type:	EmptyDir (a temporary directory that shares a pod's lifetime)
        Medium:	
      default-token-cycb6:
        Type:	Secret (a secret that should populate this volume)
        SecretName:	default-token-cycb6
    No events.

查询Couchbase样本桶

  • 登录“ Vagrant”框:
    vagrant ssh
    Last login: Wed Nov 18 18:04:32 2015 from 10.0.2.2
    [vagrant@localhost ~]$
  • 查找所有正在运行的容器的列表:
    [vagrant@localhost ~]$ docker ps
    CONTAINER ID        IMAGE                                                                                                                  COMMAND                  CREATED             STATUS              PORTS                    NAMES
    bd51f655c2a5        arungupta/couchbase@sha256:9131c5a283d79e11b6556c94b0b0f8ceba7daf5ba5982bac850100099019959f                            "/entrypoint.sh /opt/"   7 minutes ago       Up 7 minutes                                 k8s_couchbase.f96da262_couchbase-1-5zhju_default_48e953db-a66c-11e5-8a75-080027c5bfa9_31dbcfec
    8e5ef3e54d4e        openshift/origin-pod:v1.1                                                                                              "/pod"                   8 minutes ago       Up 8 minutes                                 k8s_POD.d7dfee57_couchbase-1-5zhju_default_48e953db-a66c-11e5-8a75-080027c5bfa9_b1bcd72d
    0f7807f389d9        openshift/mysql-55-centos7:latest                                                                                      "container-entrypoint"   15 minutes ago      Up 15 minutes                                k8s_ruby-helloworld-database.448eeefe_database-1-w51ix_turbo_91adac2f-8d66-11e5-bf15-080027c5bfa9_74ecdc59
    077a078e00a3        172.30.236.154:5000/turbo/origin-ruby-sample@sha256:c4ed12ec9817fca1fb41a5eb0c66f2edccf2e7375128fd6d64f7180207262193   "container-entrypoint"   16 minutes ago      Up 16 minutes                                k8s_ruby-helloworld.88353f9f_frontend-2-1lm99_turbo_42a6dd40-8d67-11e5-bf15-080027c5bfa9_d5110e41
    e2105f2f4ab6        openshift/origin-haproxy-router:v1.1                                                                                   "/usr/bin/openshift-r"   16 minutes ago      Up 16 minutes                                k8s_router.c3a638e8_router-1-5grim_default_cac8c2d2-8d63-11e5-b835-080027c5bfa9_9d49a633
    b98052109d08        172.30.236.154:5000/turbo/origin-ruby-sample@sha256:c4ed12ec9817fca1fb41a5eb0c66f2edccf2e7375128fd6d64f7180207262193   "container-entrypoint"   16 minutes ago      Up 16 minutes                                k8s_ruby-helloworld.88353f9f_frontend-2-hdz43_turbo_46657993-8d67-11e5-bf15-080027c5bfa9_f6394539
    646dcce91f59        openshift/origin-docker-registry:v1.1                                                                                  "/bin/sh -c 'REGISTRY"   16 minutes ago      Up 16 minutes                                k8s_registry.35eb136e_docker-registry-1-imxqp_default_cb3dde6e-8d63-11e5-b835-080027c5bfa9_71586c07
    d02c8c07f690        openshift/origin-registry-proxy                                                                                        "sh -cx '/bin/tcppm -"   16 minutes ago      Up 16 minutes                                k8s_openshift-registry-proxy-1.a0457375_openshift-registry-proxy_default_767fcb12-8d64-11e5-bf15-080027c5bfa9_4c413a10
    23267082944f        openshift/origin-pod:v1.1                                                                                              "/pod"                   17 minutes ago      Up 16 minutes                                k8s_POD.d982fd5f_database-1-w51ix_turbo_91adac2f-8d66-11e5-bf15-080027c5bfa9_8fc2969f
    bd7f82a88cb1        openshift/origin-pod:v1.1                                                                                              "/pod"                   17 minutes ago      Up 16 minutes                                k8s_POD.e127fd63_frontend-2-1lm99_turbo_42a6dd40-8d67-11e5-bf15-080027c5bfa9_3f73ddf8
    d2ca01d75a0c        openshift/origin-pod:v1.1                                                                                              "/pod"                   17 minutes ago      Up 16 minutes                                k8s_POD.4d0ddc3f_router-1-5grim_default_cac8c2d2-8d63-11e5-b835-080027c5bfa9_036343da
    5e25f5ba5c4c        openshift/origin-pod:v1.1                                                                                              "/pod"                   17 minutes ago      Up 16 minutes                                k8s_POD.e127fd63_frontend-2-hdz43_turbo_46657993-8d67-11e5-bf15-080027c5bfa9_122e502e
    7c4b2b9e6c39        openshift/origin-pod:v1.1                                                                                              "/pod"                   17 minutes ago      Up 16 minutes                                k8s_POD.cc3ffd58_docker-registry-1-imxqp_default_cb3dde6e-8d63-11e5-b835-080027c5bfa9_0ae24ed7
    85c4cf8d0808        openshift/origin-pod:v1.1                                                                                              "/pod"                   17 minutes ago      Up 16 minutes       0.0.0.0:5000->5000/tcp   k8s_POD.c686fded_openshift-registry-proxy_default_767fcb12-8d64-11e5-bf15-080027c5bfa9_04225f94

    搜索Couchbase容器:

    [vagrant@localhost ~]$ docker ps | grep couchbase
    CONTAINER ID        IMAGE                                                                                                                  COMMAND                  CREATED             STATUS              PORTS                    NAMES
    bd51f655c2a5        arungupta/couchbase@sha256:9131c5a283d79e11b6556c94b0b0f8ceba7daf5ba5982bac850100099019959f                            "/entrypoint.sh /opt/"   7 minutes ago       Up 7 minutes                                 k8s_couchbase.f96da262_couchbase-1-5zhju_default_48e953db-a66c-11e5-8a75-080027c5bfa9_31dbcfec
    8e5ef3e54d4e        openshift/origin-pod:v1.1                                                                                              "/pod"                   8 minutes ago       Up 8 minutes                                 k8s_POD.d7dfee57_couchbase-1-5zhju_default_48e953db-a66c-11e5-8a75-080027c5bfa9_b1bcd72d
    0f7807f389d9        openshift/mysql-55-centos7:latest                                                                                      "container-entrypoint"   15 minutes ago      Up 15 minutes

    获取我们的容器的ID:

    docker ps | grep arungupta/couchbase | awk '{ print $1}'
    bd51f655c2a5
  • 获取运行Couchbase服务器的Pod的IP地址:
    [vagrant@localhost ~]$ docker inspect --format '{{ index .Config.Env 6 }}' `docker ps | grep arungupta/couchbase | awk '{ print $1}'`
    COUCHBASE_SERVICE_HOST=172.30.84.134
  • 使用上面显示的IP地址启动Couchbase查询CLI:
    [vagrant@localhost ~]$ docker run -it arungupta/couchbase /opt/couchbase/bin/cbq -engine=http://172.30.84.134:8093
    Unable to find image 'arungupta/couchbase:latest' locally
    Trying to pull repository docker.io/arungupta/couchbase ... latest: Pulling from arungupta/couchbase
    62baed0d0de5: Already exists 
    39387babd60f: Already exists 
    6a2bc8404be0: Already exists 
    bad926a6fb50: Already exists 
    1a86c4c907e0: Already exists 
    32132a7c82e9: Already exists 
    646c3d5ebb71: Already exists 
    864cbabd77ad: Already exists 
    8c327c6d4e43: Already exists 
    8592c697ab61: Already exists 
    7734f4a832d4: Already exists 
    35edb38ebc17: Already exists 
    99f3eb6fb46f: Already exists 
    91e5fad693c2: Already exists 
    0cb81f5cc79b: Already exists 
    ec58df60a109: Already exists 
    c9d204bb7542: Already exists 
    Digest: sha256:9131c5a283d79e11b6556c94b0b0f8ceba7daf5ba5982bac850100099019959f
    Status: Downloaded newer image for docker.io/arungupta/couchbase:latest
    
    Couchbase query shell connected to http://172.30.84.134:8093/ . Type Ctrl-D to exit.
    cbq>;
  • 查询样本桶:
    cbq> select * from `travel-sample` limit 1;
    {
        "requestID": "a7bd414a-c571-4b22-8c81-30512b87730d",
        "signature": {
            "*": "*"
        },
        "results": [
            {
                "travel-sample": {
                    "callsign": "MILE-AIR",
                    "country": "United States",
                    "iata": "Q5",
                    "icao": "MLA",
                    "id": 10,
                    "name": "40-Mile Air",
                    "type": "airline"
                }
            }
        ],
        "status": "success",
        "metrics": {
            "elapsedTime": "123.799956ms",
            "executionTime": "116.882044ms",
            "resultCount": 1,
            "resultSize": 300
        }
    }

请享用!

该博客显示了OpenShift 3上Couchbase入门的基本知识。未来的博客将显示:

  • 如何将应用程序部署到OpenShift并使用此Couchbase
  • 如何使此应用程序可在OpenShift外部访问
  • 如何在OpenShift中缩放Couchbase
  • 可能还会出现其他一些有趣的项目

阅读有关Couchbase 4.1的更多信息

翻译自: https://www.javacodegeeks.com/2015/12/couchbase-openshift-3.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值