title: How to deploy a node.js with redis on kubernetes?
body: <p>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.</p>
  
  <p>From my understanding, I need a kubernetes Pod for my app, based on the docker image. Here's my Dockerfile:</p>
  
  <pre><code>FROM node:8.9.1
  WORKDIR /usr/src/app
  COPY package*.json ./
  RUN npm install
  COPY . .
  EXPOSE 8080
  CMD ["npm", "start"]
  </code></pre>
  
  <p>I build the docker image with <code>docker build -t my-app .</code></p>
  
  <p>Next, I created a Pod definition for my app's Pod:</p>
  
  <pre><code>apiVersion: v1
  kind: Pod
  metadata:
    name: my-app
  spec:
    containers:
    - name: my-app
      image: my-app:latest
      imagePullPolicy: Never
      ports:
      - containerPort: 8080
  </code></pre>
  
  <p>So far, so good. But from now on, I have no clear idea how to proceed with redis:</p>
  
  <ol>
  <li><p>should redis be another Pod, or a Service (in terms of Kubernetes kind)?</p></li>
  <li><p>How do I reference redis from inside my app? Based on whether redis will be defined as a Pod/Service, how do I obtain a connection URL and port? I read about environment variables being created by Kubernetes, but I am not sure whether these work for Pods or Services.</p></li>
  <li><p>How do I aggregate both (my app &amp; redis) under single configuration? How do I make sure that redis starts first, then my app (which requires running redis instance), and how do I expose my HTTP endpoints to the "outside world"? I read about Deployments, but I am not sure how to connect these pieces together.</p></li>
  </ol>
  
  <p>Ideally, I would like to have all configurations inside YAML files, so that at the end of the day the whole infrastructure could be started with a single command.</p>