Skip to content

Instantly share code, notes, and snippets.

@jovemfelix
Created September 27, 2022 12:16
Show Gist options
  • Save jovemfelix/d3522d81d79d726f4312a2bc4f05c9a3 to your computer and use it in GitHub Desktop.
Save jovemfelix/d3522d81d79d726f4312a2bc4f05c9a3 to your computer and use it in GitHub Desktop.
APICAST_NS=rfelix-apicast-demo
ADMIN_NS=iib-3scale-apim

APICAST_NAME=demo-apicast-staging

ACCESS_TOKEN="676c89e4da74d32d211dbb5b12d18a1f4bc6ff796ef737f60a75219b45c91240"
BASE_URL=$(oc whoami --show-console | awk -F. '{sub($1 FS, ".")}1')
ADMIN_URL="3scale-admin${BASE_URL}"
APICAST_SECRET_NAME=apicast-secret

3scale Token

oc create secret generic $APICAST_SECRET_NAME --from-literal=AdminPortalURL=https://${ACCESS_TOKEN}@${ADMIN_URL} -n $APICAST_NS

APIcast

cat <<EOF | oc apply -f -
---
apiVersion: apps.3scale.net/v1alpha1
kind: APIcast
metadata:
  name: ${APICAST_NAME}
  namespace: ${APICAST_NS}
spec:
  adminPortalCredentialsRef:
    name: ${APICAST_SECRET_NAME}
  deploymentEnvironment: staging
  extendedMetrics: true
  exposedHost:
    host: "custom-apicast${BASE_URL}"
    tls:
      - {}
  resources:
    limits:
      cpu: '0'
      memory: 128Mi
EOF

Service

cat <<EOF | oc apply -f -
---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: apicast
    monitoring: apicast
    threescale_component: apicast
  name: metrics-${APICAST_NAME}
  namespace: ${APICAST_NS}
spec:
  ports:
  - name: metrics
    port: 9421
    targetPort: metrics
  selector:
    deployment: apicast-${APICAST_NAME}
EOF

Check them

$ oc get all -l app=apicast  -l monitoring=apicast
NAME                                             TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
service/metrics-iib-externo-apicast-production   ClusterIP   10.152.104.187   <none>        9421/TCP   21h
service/metrics-iib-externo-apicast-staging      ClusterIP   10.152.200.70    <none>        9421/TCP   21h

Service Monitor

cat <<EOF | oc apply -f -
---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  labels:
    k8s-app: prometheus-apicast-monitor
  name: prometheus-apicast-monitor
  namespace: ${APICAST_NS}
spec:
  endpoints:
  - interval: 5s
    path: /metrics
    port: metrics
    scheme: http
  namespaceSelector:
    matchNames:
    - ${APICAST_NS}
  selector:
    matchLabels:
      app: apicast
      monitoring: apicast
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment