OpenShift is Red Hat’s open source PaaS platform. OpenShift 3 provides a holistic experience of running your applications using Docker and Kubernetes. In a classic Red Hat way, all the work is done in the open source at OpenShift Origin. This also drives the next major release of OpenShift Online and OpenShift Enterprise.
OpenShift 3 using Docker and Kubernetes for container orchestration makes it really simple to bring any products that have a Docker image to run with minimal effort. This blog explains how to get started with Couchbase on OpenShift 3.
Getting Started with OpenShift 3
- Download the latest Vagrant box (1.1 as of this writing) and Vagrantfile from: openshift.org/vm/. Copy them in the same directory.Vagrantfile is configured for 2GB memory and can be updated if you need to run more containers. OpenShift Master, Node, Docker Registry, and other components run inside the VM.This blog was written using Vagrant 1.7.4 and VirtualBox 5.0.10r104061.
- Add the Vagrant Box:
1234567vagrant 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'! - Start the Virtual Machine:
123456789101112131415161718192021222324252627282930313233vagrant upBringing 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:2222default: SSH username: vagrantdefault: SSH auth method: private keydefault: 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 ofdefault: VirtualBox! In most cases this is fine, but in rare cases it candefault: prevent things such as shared folders from working properly. If you seedefault: shared folder errors, please make sure the guest additions within thedefault: virtual machine match the version of VirtualBox you have installed ondefault: your host and reload your VM.default:default: Guest Additions Version: 4.3.20default: VirtualBox Version: 5.0
Download and Configure OpenShift 3 Client
- Download Mac 64-bit client tools (
gem install rhc
is for v2 only) from openshift.org/vm/ and extract them a in directory. The listing looks like:
12345678910111213tar xzvf ~/Downloads/openshift-origin-v1.1-ac7a99a-darwin-amd64.tar.gzx ./x ./oadmx ./kube-schedulerx ./kubeletx ./kube-apiserverx ./openshiftx ./kube-controller-managerx ./kube-proxyx ./ocx ./kubectl - Verify the client version:
12345./oc versionoc v1.1kubernetes v1.1.0-origin-1107-g4c8e6f4 - Remove
~/.kube/config
or rename to something else. - Login to OpenShift:
123456789101112131415161718192021./oc loginServer [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): yAuthentication required for https://localhost:8443 (openshift)Username: adminPassword:Login successful.You have access to the following projects and can switch between them with 'oc project <projectname>':* default (current)* openshift* turboUsing project "default".Welcome! See 'oc help' to get started.
Create Couchbase Application in OpenShift 3
- Create a new Couchbase instance:
12345678910111213./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" createdDeploymentConfig "couchbase" createdService "couchbase" created--> SuccessRun 'oc status' to view your app.arungupta/couchbase
is used as it uses Couchbase REST API to preconfigure the Couchbase server with:- Memory and index quota
- Query, Data, and Index service
- Username and password credentials
- Install
travel-sample
bucket
This sample bucket will be used later for querying data.
- Check the status of deployment:
1234567891011121314151617181920212223242526./oc statusIn project default on server https://localhost:8443svc/couchbase - 172.30.84.134 ports 8091, 8092, 8093, 11207, 11210, 11211, 18091, 18092dc/couchbase deploys imagestreamtag/couchbase:latest#1 deployed about a minute ago - 1 podsvc/docker-registry - 172.30.236.154:5000dc/docker-registry deploys docker.io/openshift/origin-docker-registry:v1.1#1 deployed 4 weeks ago - 1 podsvc/kubernetes - 172.30.0.1 ports 443, 53, 53svc/router - 172.30.233.69:80dc/router deploys docker.io/openshift/origin-haproxy-router:v1.1#1 deployed 4 weeks ago - 1 podWarnings:* 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 timesTo see more, use 'oc describe <resource>/<name>'.You can use 'oc get all' to see a list of other objects.
- Find the list of Pods:
12345678client > ./oc get poNAME READY STATUS RESTARTS AGEcouchbase-1-5zhju 1/1 Running 0 1ddocker-registry-1-imxqp 1/1 Running 5 32dopenshift-registry-proxy 1/1 Running 3 32drouter-1-5grim 1/1 Running 5 32d
- Get more details about the Couchbase pod:
1234567891011121314151617181920212223242526272829303132333435363738./oc describe po couchbase-1-5zhjuName: couchbase-1-5zhjuNamespace: defaultImage(s): arungupta/couchbase@sha256:9131c5a283d79e11b6556c94b0b0f8ceba7daf5ba5982bac850100099019959fNode: localhost.localdomain/10.0.2.15Start Time: Sat, 19 Dec 2015 08:19:31 -0800Labels: app=couchbase,deployment=couchbase-1,deploymentconfig=couchbaseStatus: RunningReason:Message:IP: 172.17.0.7Replication Controllers: couchbase-1 (1/1 replicas created)Containers:couchbase:Container ID: docker://bd51f655c2a54f92f4634b84f455ca91642a88b925be39126f07df43ce883a33Image: arungupta/couchbase@sha256:9131c5a283d79e11b6556c94b0b0f8ceba7daf5ba5982bac850100099019959fImage ID: docker://c9d204bb75427500ef94263f8f53e8b78f2e56efd37543e620aebb1bc1bd7de1QoS Tier:cpu: BestEffortmemory: BestEffortState: RunningStarted: Sat, 19 Dec 2015 08:20:21 -0800Ready: TrueRestart Count: 0Environment Variables:Conditions:Type StatusReady TrueVolumes: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-cycb6No events.
Query Couchbase Sample Bucket
- Log into the Vagrant box:
12345vagrant sshLast login: Wed Nov 18 18:04:32 2015 from 10.0.2.2[vagrant@localhost ~]$
- Find a list of all the running containers:
123456789101112131415161718[vagrant@localhost ~]$ docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESbd51f655c2a5 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_31dbcfec8e5ef3e54d4e openshift/origin-pod:v1.1 "/pod" 8 minutes ago Up 8 minutes k8s_POD.d7dfee57_couchbase-1-5zhju_default_48e953db-a66c-11e5-8a75-080027c5bfa9_b1bcd72d0f7807f389d9 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_74ecdc59077a078e00a3 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_d5110e41e2105f2f4ab6 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_9d49a633b98052109d08 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_f6394539646dcce91f59 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_71586c07d02c8c07f690 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_4c413a1023267082944f openshift/origin-pod:v1.1 "/pod" 17 minutes ago Up 16 minutes k8s_POD.d982fd5f_database-1-w51ix_turbo_91adac2f-8d66-11e5-bf15-080027c5bfa9_8fc2969fbd7f82a88cb1 openshift/origin-pod:v1.1 "/pod" 17 minutes ago Up 16 minutes k8s_POD.e127fd63_frontend-2-1lm99_turbo_42a6dd40-8d67-11e5-bf15-080027c5bfa9_3f73ddf8d2ca01d75a0c openshift/origin-pod:v1.1 "/pod" 17 minutes ago Up 16 minutes k8s_POD.4d0ddc3f_router-1-5grim_default_cac8c2d2-8d63-11e5-b835-080027c5bfa9_036343da5e25f5ba5c4c openshift/origin-pod:v1.1 "/pod" 17 minutes ago Up 16 minutes k8s_POD.e127fd63_frontend-2-hdz43_turbo_46657993-8d67-11e5-bf15-080027c5bfa9_122e502e7c4b2b9e6c39 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_0ae24ed785c4cf8d0808 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
Search for Couchbase container:
1234567[vagrant@localhost ~]$ docker ps | grep couchbaseCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESbd51f655c2a5 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_31dbcfec8e5ef3e54d4e openshift/origin-pod:v1.1 "/pod" 8 minutes ago Up 8 minutes k8s_POD.d7dfee57_couchbase-1-5zhju_default_48e953db-a66c-11e5-8a75-080027c5bfa9_b1bcd72d0f7807f389d9 openshift/mysql-55-centos7:latest "container-entrypoint" 15 minutes ago Up 15 minutesGet the id for our container:
1234docker ps | grep arungupta/couchbase | awk '{ print $1}'bd51f655c2a5 - Get IP address of the Pod where Couchbase server is running:
1234[vagrant@localhost ~]$ docker inspect --format '{{ index .Config.Env 6 }}' `docker ps | grep arungupta/couchbase | awk '{ print $1}'`COUCHBASE_SERVICE_HOST=172.30.84.134
- Use the IP address shown above to start Couchbase Query CLI:
123456789101112131415161718192021222324252627[vagrant@localhost ~]$ docker run -it arungupta/couchbase /opt/couchbase/bin/cbq -engine=http://172.30.84.134:8093Unable to find image 'arungupta/couchbase:latest' locallyTrying to pull repository docker.io/arungupta/couchbase ... latest: Pulling from arungupta/couchbase62baed0d0de5: Already exists39387babd60f: Already exists6a2bc8404be0: Already existsbad926a6fb50: Already exists1a86c4c907e0: Already exists32132a7c82e9: Already exists646c3d5ebb71: Already exists864cbabd77ad: Already exists8c327c6d4e43: Already exists8592c697ab61: Already exists7734f4a832d4: Already exists35edb38ebc17: Already exists99f3eb6fb46f: Already exists91e5fad693c2: Already exists0cb81f5cc79b: Already existsec58df60a109: Already existsc9d204bb7542: Already existsDigest: sha256:9131c5a283d79e11b6556c94b0b0f8ceba7daf5ba5982bac850100099019959fStatus: Downloaded newer image for docker.io/arungupta/couchbase:latestCouchbase query shell connected to http://172.30.84.134:8093/ . Type Ctrl-D to exit.cbq>
- Query the sample bucket:
1234567891011121314151617181920212223242526272829cbq> 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}}
Enjoy!
This blog shows the very basics of getting started with Couchbase on OpenShift 3. Future blogs will show:
- How to deploy an application to OpenShift and use this Couchbase
- How to make this application accessible outside OpenShift
- How to scale Couchbase in OpenShift
- Possibly some other interesting items that come along
Do you have a suggestion on what you’d like to see?
Read more about Couchbase 4.1:
- What’s New in Couchbase Server 4.1
- Download Couchbase Server 4.1
- Couchbase Server documentation
- Talk to us on Couchbase Forums
- Follow @couchbasedev or @couchbase
Hi Arun,
Thanks for the wonderful blog. What is k8_POD running for? I have seen for each container I run, there is an extra pod k8s_POD starts along with it.
Thanks in advance
Yogesh kad
9730474773
I know that on https://college-homework-help.org/blog/career-choice you will learn more about making career choices. I had such experience recently