Home Explore Blog CI



docker

1st chunk of `content/guides/nodejs/deploy.md`
b0cad0296cff2b3a51f6ff76e95f115f66aa1246853b7b7600000001000008ce
---
title: Test your Node.js deployment
linkTitle: Test your deployment
weight: 50
keywords: deploy, kubernetes, node, node.js
description: Learn how to deploy locally to test and debug your Kubernetes deployment
aliases:
  - /language/nodejs/deploy/
  - /guides/language/nodejs/deploy/
---

## Prerequisites

- Complete all the previous sections of this guide, starting with [Containerize a Node.js application](containerize.md).
- [Turn on Kubernetes](/manuals/desktop/features/kubernetes.md#install-and-turn-on-kubernetes) in Docker Desktop.

## Overview

In this section, you'll learn how to use Docker Desktop to deploy your
application to a fully-featured Kubernetes environment on your development
machine. This allows you to test and debug your workloads on Kubernetes locally
before deploying.

## Create a Kubernetes YAML file

In the cloned repository's directory, create a file named
`docker-node-kubernetes.yaml`. Open the file in an IDE or text editor and add
the following contents. Replace `DOCKER_USERNAME/REPO_NAME` with your Docker
username and the name of the repository that you created in [Configure CI/CD for
your Node.js application](configure-ci-cd.md).

```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: docker-nodejs-demo
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      todo: web
  template:
    metadata:
      labels:
        todo: web
    spec:
      containers:
        - name: todo-site
          image: DOCKER_USERNAME/REPO_NAME
          imagePullPolicy: Always
---
apiVersion: v1
kind: Service
metadata:
  name: todo-entrypoint
  namespace: default
spec:
  type: NodePort
  selector:
    todo: web
  ports:
    - port: 3000
      targetPort: 3000
      nodePort: 30001
```

In this Kubernetes YAML file, there are two objects, separated by the `---`:

- A Deployment, describing a scalable group of identical pods. In this case,
  you'll get just one replica, or copy of your pod. That pod, which is
  described under `template`, has just one container in it. The container is
  created from the image built by GitHub Actions in [Configure CI/CD for your
  Node.js application](configure-ci-cd.md).
- A NodePort service, which will route traffic from port 30001 on your host to

Title: Test Your Node.js Deployment Locally with Kubernetes
Summary
This section guides you through deploying your Node.js application to a local Kubernetes environment using Docker Desktop. Before you begin, make sure you have completed the previous steps of this guide and have Kubernetes turned on in Docker Desktop. You will create a `docker-node-kubernetes.yaml` file, containing a Deployment (describing a scalable pod) and a NodePort service (routing traffic from your host to the pod).