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

前端 未结 5 2090
长发绾君心
长发绾君心 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条回答
  •  梦毁少年i
    2021-01-12 19:58

    I think I figured out a solution (using a Deployment and a Service).

    For my deployment, I used two containers (webapp + redis) within one Pod, since it doesn't make sense for a webapp to run without active redis instance, and additionally it connects to redis upon application start. I could be wrong in this reasoning, so feel free to correct me if you think otherwise.

    Here's my deployment:

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: my-app-deployment
    spec:
      selector:
        matchLabels:
          app: my-app-deployment
      template:
        metadata:
          labels:
            app: my-app-deployment
        spec:
          containers:
          - name: redis
            image: redis:latest
            ports:
            - containerPort: 6379
            volumeMounts:
            - mountPath: /srv/www
              name: redis-storage
          - name: my-app
            image: my-app:latest
            imagePullPolicy: Never
            ports:
            - containerPort: 8080
          volumes:
          - name: redis-storage
            emptyDir: {}
    

    And here's the Service definition:

    apiVersion: v1
    kind: Service
    metadata:
      name: my-app-service
    spec:
      ports:
      - port: 8080
        protocol: TCP
      type: NodePort
      selector:
        app: my-app-deployment
    

    I create the deployment with: kubectl create -f deployment.yaml Then, I create the service with kubectl create -f service.yaml I read the IP with minikube ip and extract the port from the output of kubectl describe service my-app-service.

提交回复
热议问题