Home Explore Blog CI



docker

1st chunk of `content/guides/r/deploy.md`
85a5ffd7e7e51ea61b82975add3dbfbc0fe81026e103c5fc00000001000008ea
---
title: Test your R deployment
linkTitle: Test your deployment
weight: 50
keywords: deploy, kubernetes, R
description: Learn how to develop locally using Kubernetes
aliases:
  - /language/r/deploy/
  - /guides/language/r/deploy/
---

## Prerequisites

- Complete all the previous sections of this guide, starting with [Containerize a R 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 your `r-docker-dev` directory, create a file named
`docker-r-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 R application](configure-ci-cd.md).

```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: docker-r-demo
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      service: shiny
  template:
    metadata:
      labels:
        service: shiny
    spec:
      containers:
        - name: shiny-service
          image: DOCKER_USERNAME/REPO_NAME
          imagePullPolicy: Always
          env:
            - name: POSTGRES_PASSWORD
              value: mysecretpassword
---
apiVersion: v1
kind: Service
metadata:
  name: service-entrypoint
  namespace: default
spec:
  type: NodePort
  selector:
    service: shiny
  ports:
    - port: 3838
      targetPort: 3838
      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 R application](configure-ci-cd.md).
- A NodePort service, which will route traffic from port 30001 on your host to

Title: Testing Your R Deployment with Kubernetes on Docker Desktop
Summary
This section guides you through deploying your R application to a local Kubernetes environment using Docker Desktop for testing and debugging. It involves creating a `docker-r-kubernetes.yaml` file that defines a Deployment (for the R application) and a NodePort service (for routing traffic to the application). Remember to replace `DOCKER_USERNAME/REPO_NAME` with your Docker Hub credentials.