Home Explore Blog CI



docker

2nd chunk of `content/guides/nodejs/deploy.md`
f27afd1edfbd1d9ec3504c880933b9a93ef3836856fd2bd30000000100000ca2
  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
  port 3000 inside the pods it routes to, allowing you to reach your app
  from the network.

To learn more about Kubernetes objects, see the [Kubernetes documentation](https://kubernetes.io/docs/home/).

## Deploy and check your application

1. In a terminal, navigate to where you created `docker-node-kubernetes.yaml`
   and deploy your application to Kubernetes.

   ```console
   $ kubectl apply -f docker-node-kubernetes.yaml
   ```

   You should see output that looks like the following, indicating your Kubernetes objects were created successfully.

   ```shell
   deployment.apps/docker-nodejs-demo created
   service/todo-entrypoint created
   ```

2. Make sure everything worked by listing your deployments.

   ```console
   $ kubectl get deployments
   ```

   Your deployment should be listed as follows:

   ```shell
   NAME                 READY   UP-TO-DATE   AVAILABLE   AGE
   docker-nodejs-demo   1/1     1            1           6s
   ```

   This indicates all one of the pods you asked for in your YAML are up and running. Do the same check for your services.

   ```console
   $ kubectl get services
   ```

   You should get output like the following.

   ```shell
   NAME              TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
   kubernetes        ClusterIP   10.96.0.1        <none>        443/TCP          7d22h
   todo-entrypoint   NodePort    10.111.101.229   <none>        3000:30001/TCP   33s
   ```

   In addition to the default `kubernetes` service, you can see your `todo-entrypoint` service, accepting traffic on port 30001/TCP.

3. Open a browser and visit your app at `localhost:30001`. You should see your
   application.

4. Run the following command to tear down your application.

   ```console
   $ kubectl delete -f docker-node-kubernetes.yaml
   ```

## Summary

In this section, you learned how to use Docker Desktop to deploy your application to a fully-featured Kubernetes environment on your development machine.

Related information:

- [Kubernetes documentation](https://kubernetes.io/docs/home/)
- [Deploy on Kubernetes with Docker Desktop](/manuals/desktop/features/kubernetes.md)
- [Swarm mode overview](/manuals/engine/swarm/_index.md)

Title: Deploying and Testing Your Node.js Application on Kubernetes
Summary
This section details how to deploy your Node.js application to a local Kubernetes cluster using the `kubectl apply` command and the YAML file created in the previous step. It provides instructions to verify the deployment and service creation using `kubectl get deployments` and `kubectl get services`. Finally, it explains how to access the application in a browser via `localhost:30001` and how to tear down the deployment using `kubectl delete`. The section also provides links to additional Kubernetes resources.