How to deploy a node.js with redis on kubernetes?

前端 未结 5 2113
长发绾君心
长发绾君心 2021-01-12 18:57

I have a very simple node.js application (HTTP service), which \"talks\" to redis. I want to create a deployment and run it with minikube.

From my understanding, I n

5条回答
  •  长情又很酷
    2021-01-12 19:40

    I would run redis in a separate pod (i.e.: so your web app doesn't take down the redis server if itself crashes).

    Here is your redis deployment & service:

    deployment.yaml:

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: redis
    spec:
      selector:
        matchLabels:
          app: redis
      replicas: 1
      template:
        metadata:
          labels:
            app: redis
        spec:
          volumes:
            - name: host-sys
              hostPath:
                path: /sys
          initContainers:
            - name: disable-thp
              image: redis:4.0-alpine
              volumeMounts:
                - name: host-sys
                  mountPath: /host-sys
              command: ["sh", "-c", "echo never > /host-sys/kernel/mm/transparent_hugepage/enabled"]
          containers:
          - name: redis
            image: redis:4.0-alpine
            imagePullPolicy: IfNotPresent
            resources:
              requests:
                cpu: 350m
                memory: 1024Mi
            ports:
            - containerPort: 6379
    

    service.yaml:

    apiVersion: v1
    kind: Service
    metadata:
      name: redis
      labels:
        app: redis
    spec:
      ports:
      - port: 6379
        name: redis
      selector:
        app: redis
    

    Since we've exposed a kubernetes Service you can then access your redis instance by hostname, or it's "service name", which is redis.

    You can check out my kubernetes redis repository at https://github.com/mateothegreat/k8-byexamples-redis. You can simply run make install if you want the easier route.

    Good luck and if you're still stuck please reach out!

提交回复
热议问题