Skip to content

Latest commit

 

History

History
422 lines (329 loc) · 9.99 KB

02.minishift.md

File metadata and controls

422 lines (329 loc) · 9.99 KB

Minishift

Procedure for installing Minishift on MAC OS and deploying sample App

  • Install virtual box on Mac OS
$ brew cask install virtualbox
  • Install Minishift on Mac OS
$ brew cask install minishift
  • Set VirtualBox as permanent vm-driver to start Minishift
$ minishift config set vm-driver virtualbox
$ minishift config view
- vm-driver                          : virtualbox
  • Start Minishift installation
$ minishift start
or
$ minishift start --network-nameserver 8.8.8.8


# If you found error such as below, you may try other installation method: 
err     : exit status 1
output  : Getting a Docker client ...
Checking if image openshift/origin-control-plane:v3.11.0 is available ...
Pulling image openshift/origin-cli:v3.11.0
E0329 04:49:59.885386    5326 helper.go:173] Reading docker config from /home/docker/.docker/config.json failed: open /home/docker/.docker/config.json: no such file or directory, will attempt to pull image docker.io/openshift/origin-cli:v3.11.0 anonymously
error: error pulling Docker image openshift/origin-cli:v3.11.0

# Debug: 
$ minishift delete -f
$ minishift start --network-nameserver 8.8.8.8
  • Check Minishift status
$ minishift status

Minishift:  Running
Profile:    minishift
OpenShift:  Running (openshift v3.11.0+39132cb-398)
DiskUsage:  20% of 19G (Mounted On: /mnt/sda1)
CacheUsage: 1.678 GB (used by oc binary, ISO or cached images)
$ minishift addon apply admin-user
$ minishift addon list
- admin-user	 : enabled	P(0)

$ oc login -u admin
Authentication required for https://192.168.64.2:8443 (openshift)
Username: admin
Password: admin
Login successful.
  • Open the Minishift on Webconsole
$ minishift console
# For the first time, "Your Connection is not Secure" will be displayed. 
# Add the exception for your minishift console on the browser
# login with any user and any password (example: user developer, password anything)

$ minishift console --url
https://192.168.99.102:8443/console
# The shown URl should be your local minishift console URl
  • Set oc command to the minishift path
$ eval $(minishift oc-env)
$ which oc
$ oc version
oc v3.11.0+0cbc58b
kubernetes v1.11.0+d4cacc0
features: Basic-Auth

Server https://192.168.99.102:8443
kubernetes v1.11.0+d4cacc0
  • Login to OpenShift
$ oc login -u developer -p anything

You have access to the following projects and can switch between them with 'oc project <projectname>':

  * demo-project
    myproject

# You may also specify the login URL: 
$ oc login -u developer `minishift console --url`
  • Enable the Registry Route for Minishift
$ minishift addon apply registry-route
 -- Applying addon 'registry-route':
 -- Create secret directory..
 -- Creating server cert.
 -- Creating the secret for the registry certificates.
 -- Adding the secret to the registry pod’s service accounts (including the default service account)..
 -- Pausing the docker-registry service.
 -- Adding the secret volume to the registry deployment configuration.
 -- Enabling TLS by adding the environment variables to the registry deployment configuration.
 -- Updating the scheme used for the registry’s liveness probe from HTTP to HTTPS.
 -- Updating the scheme used for the registry’s readiness probe from HTTP to HTTPS.
 -- Resuming the docker-registry service.
 -- Creating passthrough route for docker-registry service....
 -- Add-on 'registry-route' created docker-registry route. Please run following commands to login to the OpenShift docker registry:
 -- $ eval $(minishift docker-env)
 -- $ eval $(minishift oc-env)

 -- $ docker login -u developer -p `oc whoami -t` docker-registry-default.192.168.99.102.nip.io
  • Login to Docker-Registry
$ docker login -u developer -p `oc whoami -t` docker-registry-default.192.168.99.102.nip.io
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
Login Succeeded

-Switch to different project

oc project

oc whoami

-Check the OpenShift Status

oc status or oc status --suggest

oc get imagestream

oc get buildconfig

oc get rc or oc get replicationcontroller

oc get service or oc get svc

oc get pods or oc get po

oc get all

-Expose app to outside

oc expose svc/nodejs-ex --hostname=www.example.com

-Get Route

oc get route

== OpenShift Cluster == -Start the OpenShift cluster

oc cluster up

oc cluster down

minishift stop

docker-machine stop

===== Project Management ===== -Show the current project context

oc project

-show all project current login has access to

oc get projects

-Show overview of current project resources

oc status

-Create a new project in Openshift and change to that context

oc new-project

-Create new project

oc new-project

-Get yaml configuration of a pod

oc get pods

oc get pod -o yaml

-Adding a collaborator

oc adm policy add-role-to-user admin

oc adm policy add-role-to-user edit

oc adm policy add-role-to-user view

collaborator = user (list by using oc whoami)

===== Image Stream =====

oc get is -n openshift is=imagestream

oc -o yaml new-app php~https://github.com/sandervanvugt/simpleapp --name=simple-app > simple-app.yaml

===== Deployment Config =====

oc get dc dc=depoloymentconfig

oc get rc rc=replicationcontroller

oc get pods

oc get pods -o wide

oc get pods --show-labels

oc describe dc

oc describe rc

oc describe pods

oc logs

===== Templates ===== -List templates

oc get templates --namespace openshift

===== Persistent Storage (PV & PVC) ===== -Access modes for persistent storage: ReadWriteOnce (RWO) The volume can be mounted as read/write by a single node. ReadOnlyMany (ROX) The volume can be mounted as read-only by many nodes. ReadWriteMany (RWX) The volume can be mounted as read/write by many nodes.

oc get pvc

�1】Setting up the NFS server:

yum install nfs-server

mkdir /storage

chown nfsnobody.nfsnobody /storage

chmod 7000 /nfsnobody

echo "/storage *(rw,async,all_squash)" >> /etc/exports

systemctl enable --now nfs-server

ufw status

�2】Create Persistent Volume (PV) -Create yaml(nfs-pv.yml) file: apiVersion: v1 kind: PersistentVolume metadata: name: nfs-pv spec: capacity: storage: 2Gi accessModes:

  • ReadWriteMany persistentVolumeReclaimPolicy: Retain nfs: path: /storage server: 172.17.0.1 readOnly: false

�3】Adding Persistent Volume (PV)

oc login -u system:admin -p anything

oc create -f nfs-pv.yml

oc get pv | grep nfs

oc describe pv nfs-pv

�4】Creating Persistent Volume Claim (PVC) -Create yaml(nfs-pvc.yml) file: kind: PersistentVolumeClaim apiVersion: v1 metadata: name: nfs-pv-claim spec: accessModes:

  • ReadWriteMany resources: requests: storage: 100Mi

�5】Creating PVC

oc whoami

oc login -u developer -p anything

oc create -f nfs-pvc.yml

oc describe pvc nfs-pv-claim

oc get pvc

�6】Creating the pod

oc create -f nfs-pv-pod.yaml

oc describe pod nfs-pv-pod

(check the Volume section, also check Events)

oc logs pod nfs-pv-pod

-Create nfs-pv-pod.yaml kind: Pod apiVersion: v1 metadata: name: nfs-pv-pod spec: volumes: - name: nfsvolume (!this name is nothing todo with pv-name) persistentVolumeClaim: claimName: nfs-pv-claim containers: - name: nfs-client1 image: toccoag/openshift-nginx ports: - containerPort: 8081 name: "http-server1" volumeMounts: - mountPath: "/mnt" name: nfsvolume resources: {} - name: nfs-client2 image: toccoag/openshift-nginx ports: - containerPort: 8082 name: "http-server2" volumeMounts: - mountPath: "/nfsshare" name: nfsvolume resources: {}

�7】Verifying current configuration

oc describe pod

oc get pvc

oc logs

oc exec -it -- sh

  • mount | grep mysql

oc logs pod/nfs-pv-pod -c nfs-client1

oc logs pod/nfs-pv-pod -c nfs-client2

===== ConfigMaps ===== ConfigMaps can be used to separate Dynamic Data from Static Data in a Pod ConfigMaps can be used in 3 different ways:

  1. make variables available within a Pod
  2. provide command line arguments
  3. mount them on the location where the application expects to find a configuration file

vim variables

VAR_1=Hello VAR_2=World esc : wq!

oc create cm variables --from-env-file=variables

oc get cm

oc describe cm variables

oc create -f test-pod1.yml

oc get pods

oc logs pod/example

-Create test-pod1.yml apiVersion: v1 kind: Pod metadata: name: example spec: containers: - name: example image: cirros command: ["/bin/sh", "-c", "env"] envFrom: - configMapRef: name: variables

===== OpenShift Troubleshoot ===== -Show recent events

oc get events

-Show what has happened to specific pod

oc logs

-Show pod details

oc describe pod

-Show current working project

oc projects

-Delete everything

oc delete all --all

oc logs -f bc/

===== Demo1 ===== oc login -u developer -p anything oc new-project firstproject oc new-app --docker-image=nginx:latest --name=nginx oc status (use it repeatedly to trace the process) oc get pods oc describe pod oc get svc oc describe service nginx oc port-forward 33080:80 curl -s http://localhost:33080

===== Demo2 ===== oc whoami oc new-project mysql oc new-app --docker-image=mysql:latest --name=mysql-openshift -e MYSQL_USER=myuser -e MYSQL_PASSWORD=password -e MYSQL_DATABASE=mydb -e MYSQL_ROOT_PASSWORD=password oc status -v oc get all oc get pods -o=wide login to the Webconsoleand see the new application https://127.0.0.1:8443

��� OPENSHIFT ���

--ConfigMap

oc edit configmap/webconsole-config -n openshift-web-console

--Sample Yaml

rpm -ql openshift-ansible-docs