<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>

mpb
<p>I think I figured out a solution (using a Deployment and a Service).</p>

<p>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.</p>

<p>Here's my deployment:</p>

<pre><code>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: {}
</code></pre>

<p>And here's the Service definition:</p>

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

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