Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SWS 155: kubernetes scripts #67

Merged
merged 1 commit into from
Feb 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 32 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,30 @@ else
fi
endif

docker: .get-console
.prepare-docker-image-files: .get-console
@echo Preparing docker image files...
@mkdir -p _output/docker
@cp -r deploy/docker/* _output/docker
@cp ${GOPATH}/bin/sws _output/docker
@echo Building Docker Image...

docker: .prepare-docker-image-files
@echo Building docker image into local docker daemon...
docker build -t ${DOCKER_TAG} _output/docker

.prepare-minikube:
@minikube addons list | grep -q "ingress: enabled" ; \
if [ "$$?" != "0" ]; then \
echo "Enabling ingress support to minikube" ; \
minikube addons enable ingress ; \
fi
@grep -q sws /etc/hosts ; \
if [ "$$?" != "0" ]; then \
echo "/etc/hosts should have SWS so you can access the ingress"; \
fi

minikube-docker: .prepare-minikube .prepare-docker-image-files
@echo Building docker image into minikube docker daemon...
@eval $$(minikube docker-env) ; \
docker build -t ${DOCKER_TAG} _output/docker

docker-push:
Expand All @@ -135,22 +154,28 @@ docker-push:
openshift-deploy: openshift-undeploy
@echo Deploying to OpenShift project ${NAMESPACE}
oc create -f deploy/openshift/sws-configmap.yaml -n ${NAMESPACE}
oc process -f deploy/openshift/sws.yaml -p IMAGE_NAME=${DOCKER_NAME} -p IMAGE_VERSION=${DOCKER_VERSION} -p NAMESPACE=${NAMESPACE} -p VERBOSE_MODE=${VERBOSE_MODE} | oc create -n ${NAMESPACE} -f -
cat deploy/openshift/sws.yaml | IMAGE_NAME=${DOCKER_NAME} IMAGE_VERSION=${DOCKER_VERSION} NAMESPACE=${NAMESPACE} VERBOSE_MODE=${VERBOSE_MODE} envsubst | oc create -n ${NAMESPACE} -f -

openshift-undeploy: .openshift-validate
@echo Undeploying from OpenShift project ${NAMESPACE}
oc delete all,secrets,sa,templates,configmaps,daemonsets,clusterroles,clusterrolebindings --selector=app=sws -n ${NAMESPACE}
oc delete all,secrets,sa,templates,configmaps,deployments,clusterroles,clusterrolebindings --selector=app=sws -n ${NAMESPACE}

openshift-reload-image: .openshift-validate
@echo Refreshing Image in OpenShift project ${NAMESPACE}
@echo Refreshing image in OpenShift project ${NAMESPACE}
oc delete pod --selector=app=sws -n ${NAMESPACE}

.k8s-validate:
@kubectl get namespace ${NAMESPACE} > /dev/null

k8s-deploy: k8s-undeploy
@echo Deploying to Kubernetes namespace ${NAMESPACE}
kubectl create -f deploy/kubernetes/sws-configmap.yaml -n ${NAMESPACE}
kubectl create -f deploy/kubernetes/sws.yaml -n ${NAMESPACE}
cat deploy/kubernetes/sws.yaml | IMAGE_NAME=${DOCKER_NAME} IMAGE_VERSION=${DOCKER_VERSION} NAMESPACE=${NAMESPACE} VERBOSE_MODE=${VERBOSE_MODE} envsubst | kubectl create -n ${NAMESPACE} -f -

k8s-undeploy:
@echo Undeploying from Kubernetes namespace ${NAMESPACE}
kubectl delete all,secrets,sa,configmaps,daemonsets,ingresses,clusterroles --selector=app=sws -n ${NAMESPACE}
kubectl delete all,secrets,sa,configmaps,deployments,ingresses,clusterroles,clusterrolebindings --selector=app=sws -n ${NAMESPACE}

k8s-reload-image: .k8s-validate
@echo Refreshing image in Kubernetes namespace ${NAMESPACE}
kubectl delete pod --selector=app=sws -n ${NAMESPACE}
25 changes: 21 additions & 4 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ make docker
==== Deploying SWS to OpenShift

[NOTE]
Before deploying and running SWS, you must install and deploy link:https://istio.io[Istio] first. There are a few places that you can reference in order to learn how to do this such as link:https://github.com/redhat-developer-demos/istio-tutorial[here], link:https://blog.openshift.com/evaluate-istio-openshift/[here], and link:https://istio.io/docs/setup/kubernetes/quick-start.html[here]. There is also a link:hack/istio-install-openshift.sh[] script to help you install Istio if you are using OpenShift.
Before deploying and running SWS, you must install and deploy link:https://istio.io[Istio] first. There are a few places that you can reference in order to learn how to do this such as link:https://github.com/redhat-developer-demos/istio-tutorial[here], link:https://blog.openshift.com/evaluate-istio-openshift/[here], and link:https://istio.io/docs/setup/kubernetes/quick-start.html[here]. There is also a link:hack/istio/openshift[OpenShift script] provided to you as a convienence to help you install Istio if you are using OpenShift.

[NOTE]
The following commands assume that the `oc` command is available in the user's path and that the user is logged in.
Expand Down Expand Up @@ -125,8 +125,8 @@ make openshift-reload-image

=== Running on Kubernetes

[WARNING]
These instructions are not fully working. Contributions are welcome to get Kubernetes deployment to work!
[NOTE]
These instructions may not fully work. Contributions are welcome.

==== Setting up Kubernetes

Expand All @@ -142,10 +142,18 @@ cd ${GOPATH}/src/github.com/swift-sunshine/swscore
make docker
----

Note that if you are using minikube, you can build the docker image and push it directly into the minikube docker daemon using the alternative make target `minikube-docker`:

[source,shell]
----
cd ${GOPATH}/src/github.com/swift-sunshine/swscore
make minikube-docker
----

==== Deploying SWS to Kubernetes

[NOTE]
Before deploying and running SWS, you must install and deploy link:https://istio.io[Istio] first. There are a few places that you can reference in order to learn how to do this such as link:https://github.com/redhat-developer-demos/istio-tutorial[here], link:https://blog.openshift.com/evaluate-istio-openshift/[here], and link:https://istio.io/docs/setup/kubernetes/quick-start.html[here].
Before deploying and running SWS, you must install and deploy link:https://istio.io[Istio] first. There are a few places that you can reference in order to learn how to do this such as link:https://github.com/redhat-developer-demos/istio-tutorial[here], link:https://blog.openshift.com/evaluate-istio-openshift/[here], and link:https://istio.io/docs/setup/kubernetes/quick-start.html[here]. There is also a link:hack/istio/kubernetes[Kubernetes script] provided to you as a convienence to help you install Istio if you are using Kubernetes.

[NOTE]
The following commands assume that the `kubectl` command is available in the user's path and that the user is logged in.
Expand All @@ -167,6 +175,15 @@ If you want to remove SWS from your Kubernetes environment, you can do so by run
make k8s-undeploy
----

==== Reloading SWS image in Kubernetes

If you already have SWS installed but you want to recreate the pod with a new docker image, you can run the following command:

[source,shell]
----
make k8s-reload-image
----

=== Running Standalone

Sometimes you may want to run SWS outside of any container environment, perhaps for debugging purposes. To do this, run:
Expand Down
4 changes: 2 additions & 2 deletions deploy/kubernetes/sws-configmap.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
kind: ConfigMap
apiVersion: v1
kind: ConfigMap
metadata:
name: sws-configuration
name: sws
labels:
app: sws
data:
Expand Down
78 changes: 64 additions & 14 deletions deploy/kubernetes/sws.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ metadata:
name: sws
labels:
app: sws
parameters:
spec:
type: NodePort
ports:
- protocol: TCP
- name: tcp
protocol: TCP
port: 20001
selector:
app: sws
Expand All @@ -32,34 +32,39 @@ spec:
servicePort: 20001
---
apiVersion: extensions/v1beta1
kind: DaemonSet
kind: Deployment
metadata:
name: sws
labels:
name: sws
app: sws
spec:
replicas: 1
selector:
matchLabels:
name: sws
app: sws
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
type: RollingUpdate
template:
metadata:
name: sws
labels:
name: sws
app: sws
spec:
serviceAccount: sws
containers:
- image: jmazzitelli/sws:latest
- image: ${IMAGE_NAME}:${IMAGE_VERSION}
name: sws
command:
- "/opt/sws/sws"
- "-config"
- "/sws-configuration/config.yaml"
- "-v"
- "5"
- "/opt/sws/sws"
- "-config"
- "/sws-configuration/config.yaml"
- "-v"
- "${VERBOSE_MODE}"
env:
- name: FOO_STRING
- name: ACTIVE_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
Expand All @@ -69,4 +74,49 @@ spec:
volumes:
- name: sws-configuration
configMap:
name: sws-configuration
name: sws
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: sws
labels:
app: sws
rules:
- apiGroups: [""]
attributeRestrictions: null
resources:
- configmaps
- namespaces
- nodes
- pods
- projects
- services
- endpoints
verbs:
- get
- list
- watch
- apiGroups: ["config.istio.io"]
attributeRestrictions: null
resources:
- routerules
verbs:
- get
- list
- watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: sws
labels:
app: sws
roleRef:
kind: ClusterRole
name: sws
apiGroup: rbac.authorization.k8s.io
subjects:
- kind: ServiceAccount
name: sws
namespace: ${NAMESPACE}
Loading