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

Deploy OpenWhisk API Gateway #10

Closed
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
2 changes: 1 addition & 1 deletion docker/routemgmt/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ fi
# Run installRouteMgmt.sh
pushd ansible/roles/routemgmt/files
./installRouteMgmt.sh $WHISK_AUTH $WHISK_API_HOST_NAME $WHISK_NAMESPACE $OPENWHISK_HOME/bin/wsk
popd
popd
146 changes: 146 additions & 0 deletions openshift/apigateway.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
########################################
## API Gateway ConfigMap
########################################
---
apiVersion: v1
kind: ConfigMap
metadata:
name: apigateway
data:
apimgmt-init: |
# Dynamically determine API gateway host
export TOKEN="$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)"
export NAMESPACE="$(cat /run/secrets/kubernetes.io/serviceaccount/namespace)"
export WHISK_API_GATEWAY_HOST=$(wget -q -O - -o /dev/null --ca-certificate='/var/run/secrets/kubernetes.io/serviceaccount/ca.crt' --header="Authorization: Bearer ${TOKEN}" "https://${KUBERNETES_SERVICE_HOST}:${KUBERNETES_SERVICE_PORT}/oapi/v1/namespaces/${NAMESPACE}/routes/openwhisk?pretty=true" | grep '"host":' | head -n 1 | awk -F '"' '{print $4}')
export WHISK_API_HOST_NAME="${WHISK_API_GATEWAY_HOST}"
export PUBLIC_GATEWAY_URL="${WHISK_API_GATEWAY_HOST}"
exec /init.sh
apigateway-init: |
# Dynamically determine API gateway host and other environment variables
export TOKEN="$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)"
export NAMESPACE="$(cat /run/secrets/kubernetes.io/serviceaccount/namespace)"
export WHISK_API_GATEWAY_HOST=$(wget -q -O - -o /dev/null --ca-certificate='/var/run/secrets/kubernetes.io/serviceaccount/ca.crt' --header="Authorization: Bearer ${TOKEN}" "https://${KUBERNETES_SERVICE_HOST}:${KUBERNETES_SERVICE_PORT}/oapi/v1/namespaces/${NAMESPACE}/routes/openwhisk?pretty=true" | grep '"host":' | head -n 1 | awk -F '"' '{print $4}')
export WHISK_API_HOST_NAME="${WHISK_API_GATEWAY_HOST}"
export PUBLIC_GATEWAY_URL="http://${WHISK_API_GATEWAY_HOST}"
# with current bug in minishift its not able to resolve short dns names
# https://github.com/minishift/minishift/issues/2070
exec env REDIS_HOST="redis.${NAMESPACE}.svc.cluster.local" /etc/init-container.sh
########################################
# START REDIS Deployment
########################################
---
apiVersion: v1
kind: Service
metadata:
labels:
app: redis
name: redis
spec:
ports:
- name: redis
port: 6379
selector:
app: redis
---
apiVersion: apps.openshift.io/v1
kind: DeploymentConfig
metadata:
labels:
app: redis
name: redis
spec:
replicas: 1
template:
metadata:
labels:
app: redis
name: redis
spec:
containers:
- image: docker.io/redis:3.2
name: redis
triggers:
- type: ConfigChange

########################################
# END REDIS Deployment
########################################

########################################
# START OpenWhisk ApiGateway Deployment
########################################
---
apiVersion: v1
kind: Service
metadata:
name: apigateway
labels:
name: apigateway
spec:
selector:
name: apigateway
ports:
- port: 8080
name: mgmt
- port: 9000
name: api
---
apiVersion: apps.openshift.io/v1
kind: DeploymentConfig
metadata:
name: apigateway
labels:
name: apigateway
spec:
replicas: 1
template:
metadata:
labels:
name: apigateway
spec:
restartPolicy: Always
serviceAccountName: openwhisk
volumes:
- name: apigateway-config
configMap:
name: apigateway
items:
- key: apigateway-init
path: init
containers:
- name: apigateway
imagePullPolicy: IfNotPresent
image: docker.io/openwhisk/apigateway
command: [ "/bin/bash", "-o", "allexport", "/apigateway-config/init" ]
ports:
- name: mgmt
containerPort: 8080
- name: api
containerPort: 9000
env:
# - name: REDIS_HOST
# value: "redis.openwhisk.svc.cluster.local"
- name: REDIS_PORT
value: "6379"
volumeMounts:
- name: apigateway-config
mountPath: "/apigateway-config"
triggers:
- type: ConfigChange

---
apiVersion: route.openshift.io/v1
kind: Route
metadata:
labels:
app: apigateway
name: apigateway
spec:
port:
targetPort: mgmt
to:
kind: Service
name: apigateway
########################################
# END OpenWhisk ApiGateway Deployment
########################################
45 changes: 45 additions & 0 deletions openshift/apimanagement.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
apiVersion: batch/v1
kind: Job
metadata:
name: install-apimanagement
spec:
activeDeadlineSeconds: 600
template:
metadata:
name: install-apimanagement
spec:
serviceAccountName: openwhisk
volumes:
- name: apimgmt-config
configMap:
name: apigateway
items:
- key: apimgmt-init
path: init
containers:
- name: apimanagement
image: docker.io/openwhisk/kube-routemgmt
command: [ "/bin/bash", "-o", "allexport", "/apimgmt-config/init" ]
imagePullPolicy: IfNotPresent
env:
- name: "WHISK_CLI_VERSION"
valueFrom:
configMapKeyRef:
name: whisk.config
key: whisk_cli_version_tag
- name: "WHISK_AUTH"
valueFrom:
secretKeyRef:
name: whisk.auth
key: system
- name: "WHISK_NAMESPACE"
valueFrom:
configMapKeyRef:
name: whisk.config
key: whisk_system_namespace
- name: "WHISK_API_GATEWAY_HOST_V2"
value: "http://$(APIGATEWAY_SERVICE_HOST):$(APIGATEWAY_SERVICE_PORT_API)/v2"
volumeMounts:
- name: apimgmt-config
mountPath: "/apimgmt-config"
restartPolicy: Never