From c7b0f2a98db8e81882a259cc44a33a9a2b9bbcd4 Mon Sep 17 00:00:00 2001 From: Steve Waterworth Date: Tue, 5 May 2020 12:22:25 +0100 Subject: [PATCH] updates for OpenShift --- K8s/helm/templates/redis-statefulset.yaml | 2 + K8s/helm/templates/web-service.yaml | 4 ++ K8s/helm/values.yaml | 6 +++ OpenShift/README.md | 29 ++++++++++---- OpenShift/deploy.sh | 48 ----------------------- OpenShift/setup.sh | 22 ++--------- README.md | 45 ++------------------- 7 files changed, 39 insertions(+), 117 deletions(-) delete mode 100755 OpenShift/deploy.sh diff --git a/K8s/helm/templates/redis-statefulset.yaml b/K8s/helm/templates/redis-statefulset.yaml index ea93d90..8fef9b6 100644 --- a/K8s/helm/templates/redis-statefulset.yaml +++ b/K8s/helm/templates/redis-statefulset.yaml @@ -39,8 +39,10 @@ spec: name: data spec: accessModes: [ "ReadWriteOnce" ] + {{ if not .Values.openshift }} storageClassName: standard volumeMode: Filesystem + {{ end }} resources: requests: storage: 1Gi diff --git a/K8s/helm/templates/web-service.yaml b/K8s/helm/templates/web-service.yaml index 260ec71..7f07a3b 100644 --- a/K8s/helm/templates/web-service.yaml +++ b/K8s/helm/templates/web-service.yaml @@ -11,4 +11,8 @@ spec: targetPort: 8080 selector: service: web + {{ if .Values.nodeport }} + type: NodePort + {{ else }} type: LoadBalancer + {{ end }} diff --git a/K8s/helm/values.yaml b/K8s/helm/values.yaml index 4451e74..25c7917 100644 --- a/K8s/helm/values.yaml +++ b/K8s/helm/values.yaml @@ -21,3 +21,9 @@ eum: psp: enabled: false +# For the mini ones minikube, minishift set to true +nodeport: false + +# "special" Openshift. Set to true when deploying to any openshift flavour +openshift: false + diff --git a/OpenShift/README.md b/OpenShift/README.md index ab14327..5c8d7ff 100644 --- a/OpenShift/README.md +++ b/OpenShift/README.md @@ -4,17 +4,30 @@ See the official [documentation](https://docs.instana.io/quick_start/agent_setup # Robot Shop Deployment -Have a look at the contents of the *setup.sh* and *deploy,sh* scripts, you may want to tweak some settings to suit your environment. +For OpenShift run the `setup.sh` script to create the project and set the extra permissions. -Run the *setup.sh* script first, you will need the passwords for the developer and system:admin users. +Use the Helm chart for Kubernetes to install Stan's Robot Shop. To install on Minishift. -Once the set up is completed, run the *deploy.sh* script. This script imports the application images from Docker Hub into OpenShift, then it creates applications from those images. +### Helm 3 -When the deployment has completed, to make Stan's Robot Shop accessible the web service needs to be updated. - -```bash -oc edit svc web +```shell +$ cd K8s +$ oc login -u developer +$ oc project robot-shop +$ helm install robot-shop --set openshift=true --set nodeport=true helm ``` -Change *type* to **NodePort** when running on Minishift or **LoadBalancer** for regular OpenShift. +To connect to the shop. + +```shell +$ minishift ip +192.168.99.106 +$ oc get svc web +NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE +web NodePort 172.30.180.253 8080:31147/TCP 4m +``` + +Use the IP and the node port to form the URL `http://192.168.99.106:31147/` + + diff --git a/OpenShift/deploy.sh b/OpenShift/deploy.sh deleted file mode 100755 index 003212b..0000000 --- a/OpenShift/deploy.sh +++ /dev/null @@ -1,48 +0,0 @@ -#!/bin/sh - -# set -x - -set -e - -# Put your EUM key here -EUM_KEY="" - - -echo "logging in as developer" -oc login -u developer -oc project robot-shop - -# set the environment from the .env file -for VAR in $(egrep '^[A-Z]+=' ../.env) -do - export $VAR -done - -# import all the images from docker hub into OpenShift -for LINE in $(awk '/^ {2}[a-z]+:$/ {printf "%s", $0} /image: / {print $2}' ../docker-compose.yaml) -do - NAME=$(echo "$LINE" | cut -d: -f1) - IMAGE=$(echo "$LINE" | cut -d: -f2-) - FULL_IMAGE=$(eval "echo $IMAGE") - - echo "NAME $NAME" - echo "importing $FULL_IMAGE" - - oc import-image $FULL_IMAGE --from $FULL_IMAGE --confirm - # a bit of a hack but appears to work - BASE=$(basename $FULL_IMAGE) - oc new-app -i $BASE --name $NAME -done - -# Set EUM environment if required -if [ -n "$EUM_KEY" ] -then - oc set env dc/web INSTANA_EUM_KEY=$EUM_KEY -fi - -echo " " -echo "Deployment complete" -echo "To make Robot Shop accessible, please run " -echo "Change type from ClusterIP to NodePort on minishift or LoadBalancer on OpenShift" -echo " " - diff --git a/OpenShift/setup.sh b/OpenShift/setup.sh index 5ef0a2b..4c7e2da 100755 --- a/OpenShift/setup.sh +++ b/OpenShift/setup.sh @@ -1,28 +1,12 @@ #!/bin/sh -# Put your EUM key here -EUM_KEY="" - # set -x -# This only works for default local install of minishift -# Need to tweak some settings in OpenShift -echo "logging in as system:admin" oc login -u system:admin - -# Optionally label the nodes with role infra -for NODE in $(oc get node | awk '{if ($3 == "infra" || $3 == "") print $1}' -) -do - oc label node $NODE 'type=infra' -done - -oc adm new-project robot-shop --node-selector='type=infra' +oc adm new-project robot-shop oc adm policy add-role-to-user admin developer -n robot-shop oc adm policy add-scc-to-user anyuid -z default +oc adm policy add-scc-to-user privileged -z default -oc logout - -echo " " -echo "OpenShift set up complete, ready to deploy Robot Shop now." -echo " " +oc login -u developer diff --git a/README.md b/README.md index f006cdd..26c6d7b 100644 --- a/README.md +++ b/README.md @@ -70,57 +70,18 @@ You can run Kubernetes locally using [minikube](https://github.com/kubernetes/mi The Docker container images are all available on [Docker Hub](https://hub.docker.com/u/robotshop/). -Install Stan's Robot Shop to your Kubernetes cluster using the helm chart. - -```shell -$ cd K8s/helm -$ helm install --name robot-shop --namespace robot-shop . -``` - -There are some customisations that can be made see the [README](K8s/helm/README.md). +Install Stan's Robot Shop to your Kubernetes cluster using the [Helm](K8s/helm/README.md) chart. To deploy the Instana agent to Kubernetes, just use the [helm](https://hub.helm.sh/charts/stable/instana-agent) chart. -```shell -$ helm install --name instana-agent --namespace instana-agent \ ---set agent.key=INSTANA_AGENT_KEY \ ---set agent.endpointHost=HOST \ ---set agent.endpointPort=PORT \ ---set zone.name=CLUSTER_NAME \ -stable/instana-agent -``` - -If you are having difficulties getting helm running with your K8s install, it is most likely due to RBAC, most K8s now have RBAC enabled by default. Therefore helm requires a [service account](https://github.com/helm/helm/blob/master/docs/rbac.md) to have permission to do stuff. - ## Accessing the Store If you are running the store locally via *docker-compose up* then, the store front is available on localhost port 8080 [http://localhost:8080](http://localhost:8080/) -If you are running the store on Kubernetes via minikube then, to make the store front accessible edit the *web* service definition and change the type to *NodePort* and add a port entry *nodePort: 30080*. - -```shell -$ kubectl -n robot-shop edit service web -``` - -Snippet - -```yaml -spec: - ports: - - name: "8080" - port: 8080 - protocol: TCP - targetPort: 8080 - nodePort: 30080 - selector: - service: web - sessionAffinity: None - type: NodePort -``` - -The store front is then available on the IP address of minikube port 30080. To find the IP address of your minikube instance. +If you are running the store on Kubernetes via minikube then, find the IP address of Minikube and the Node Port of the web service. ```shell $ minikube ip +$ kubectl get svc web ``` If you are using a cloud Kubernetes / Openshift / Mesosphere then it will be available on the load balancer of that system.