OpenShift all-in-one cluster

If you'd like to try out OpenShift, you can set up OpenShift cluster with the oc cluster up. This only works with OpenShift version 3.x

In short on Linux:

  1. Install Docker with your platform's package manager.

  2. Configure the Docker daemon with an insecure registry parameter of 172.30.0.0/16

    • Edit the /etc/docker/daemon.json file and add the following:

      {
         "insecure-registries": [
           "172.30.0.0/16"
         ]
      }
      
    • After editing the config, reload systemd and restart the Docker daemon.

      $ sudo systemctl daemon-reload
      $ sudo systemctl restart docker
      
  3. Download the Linux oc binary from
    openshift-origin-client-tools-VERSION-linux-64bit.tar.gz
    and place it in your path.

  4. Backup your .kube folder, if you want to

  5. Open a terminal with a user that has permission to run Docker commands and run:

    $ oc cluster up
    

    or if you want your data to persist

    ### VERSION 3.9
    $ oc cluster up --public-hostname $(ip route get 1 | awk '{print $7;exit}') \
                    --host-config-dir="${HOME}/.oc-cluster-up/openshift.local.config" \
                    --host-data-dir="${HOME}/.oc-cluster-up/openshift.local.data" \
                    --host-volumes-dir="${HOME}/.oc-cluster-up/openshift.local.volumes" \
                    --host-pv-dir="${HOME}/.oc-cluster-up/openshift.local.pv" \
                    --use-existing-config
                    
    ### VERSION 3.11
    # write config files
    $ oc cluster up --base-dir ${HOME}/.oc-cluster-up --public-hostname=$(ip route get 1 | awk '{print $7;exit}') --write-config
    
    # I have found that, if you're using *.nip.io for your routes, which are the default, it's a good idea to add/edit your nameserver to NOT use your router's DNS, (at least it was the case for me), so I set it to 1.1.1.1 or 8.8.8.8:
    $ sed -i 's/^#DNS=.*/DNS=1.1.1.1/g' /etc/systemd/resolved.conf
    $ systemctl restart systemd-resolved
    $ systemd-resolve --status # verify the nameservers in use
    
    # start the openshift cluster
    $ oc cluster up --base-dir=${HOME}/.oc-cluster-up --public-hostname=$(ip route get 1 | awk '{print $7;exit}')
     
    
    ### Check and see if DESIRED == CURRENT for router and docker-registry in the default namespace
    $ oc login -u system:admin
    $ oc get dc --namespace=default
    
    ### If they're not equal, then running these 2 commands usually fixes it:
    $ oc rollout latest --namespace=default deploymentconfig/router
    $ oc rollout latest --namespace=default deploymentconfig/docker-registry
    
    
    ### You can use this to update/change the IP Address to whatever IP you want to use to access your Openshift Cluster
    $ find ${HOME}/.oc-cluster-up -type f -exec sed -i "s|https://127.0.0.1:8443|https://$(ip route get 1 | awk '{print $7;exit}'):8443|g" {} \;
    $ sed -i "s|127.0.0.1.nip.io|$(ip route get 1 | awk '{print $7;exit}').nip.io|g" ${HOME}/.oc-cluster-up/openshift-apiserver/master-config.yaml
    
    
    ### ONE-LINER FOR VERSION 3.11
    # This is my one line that I use often (from scratch or when I want to delete everything and start all over)
    
    $ oc cluster down && ( sudo rm -fr ${HOME}/.oc-cluster-up ${HOME}/.kube || sudo reboot ) && oc cluster up --base-dir ${HOME}/.oc-cluster-up --public-hostname=$(ip route get 1 | awk '{print $7;exit}') --write-config && oc cluster up --base-dir=${HOME}/.oc-cluster-up --public-hostname=$(ip route get 1 | awk '{print $7;exit}')
    

    You can set --public-hostname with your hostname or IP Address. I used $(ip route get 1 | awk '{print $7;exit}') to get the IP address there...

    Tip: I've set an alias help start the cluster with:

    $ alias oc-cluster-up="oc cluster up --base-dir=${HOME}/.oc-cluster-up --public-hostname=$(ip route get 1 | awk '{print $7;exit}')"
    

    and next time I can just do: oc-cluster-up

    Once it's up, you can try it out:

    # create a project (Kubernetes namespace) for your app
    oc new-project example
    
    # stand up a CakePHP + MySQL example application using one of the preconfigured OpenShift templates
    oc new-app cakephp-mysql-example
    
    # Watch the build logs for the CakePHP source code
    oc logs -f bc/cakephp-mysql-example
    
    # See a summary of the app
    oc status
    
    # Follow the deployment logs for CakePHP
    oc logs -f dc/cakephp-mysql-example
    
    # Browse to the route (exposed via the router)
    curl http://cakephp-mysql-example-example.10.1.2.2.xip.io
    

    Watch the full asciicast

To give a user cluster-admin access:

$ oc adm policy add-cluster-role-to-user cluster-admin ${USER}

If the router doesn't get installed, which for some reason it happens, you can run (and this should get you going...):

$ oc adm router my-router --replicas=1 --service-account=router --extended-logging=true

To stop your cluster, run:

$ oc cluster down

That's it...

Comments:

For comments, please visit https://plus.google.com/u/0/+JefferyBagirimvano/posts/WMYVv1fSEPK