User:BryanDavis/Kubernetes

From Wikitech
Jump to navigation Jump to search

Fun things I have learned how to do on the Toolforge Kubernetes cluster.

Make a tool redirect to another tool WITHOUT running a webservice

This trick only works on the "new" (2020) Toolforge Kubernetes cluster. It relies on configuring the nginx-ingress system to handle the redirection.

---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: {{TOOL_NAME}}-redirect
  namespace: tool-{{TOOL_NAME}}
  labels:
    name: {{TOOL_NAME}}-redirect
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/permanent-redirect: https://tools.wmflabs.org/{{TARGET_TOOL_NAME}}/$2
spec:
  rules:
    - host: tools.wmflabs.org
      http:
        paths:
          - backend:
              serviceName: unused
              servicePort: 8000
            path: /{{TOOL_NAME}}(/|$)(.*)
$ kubectl create --validate=true -f ingress.yaml
ingress.extensions/grid-jobs-redirect created

Run multiple pods for your webservice

Have a webservice that is under a lot of load? Scale it up!

$ kubectl scale --replicas=2 $(kubectl get deployment -o name)

Attach to a running pod

webservice --backend=kubernetes [runtime] shell will give you a shell inside a fresh Kubernetes pod, but sometimes you really want to poke around inside the pod that is running your webservice or bot.

$ kubectl exec -it $(kubectl get pods --output=jsonpath={.items..metadata.name}) -- /bin/bash