Goglides Dev 🌱

Goglides Dev 🌱 is a community of amazing users

Shaping the future of IT, one connection at a time.

Create account Log in
Cover image for Improving kubernetes development experience with Docker Telepresence
Roshan Thapa
Roshan Thapa

Posted on

Improving kubernetes development experience with Docker Telepresence

Docker Telepresence is a tool that allows you to develop and test your Kubernetes applications locally, while still having access to the resources of a remote Kubernetes cluster. This can be a great way to improve your development workflow, as it allows you to iterate on your code more quickly and easily.

Image description

This writeup will show you how to use Docker Telepresence with a technical example. We will create a simple Kubernetes application and use Telepresence to develop and test it locally.

Technical Example

We will use the following steps to create a simple Kubernetes application and use Telepresence to develop and test it locally:

  • Create a Dockerfile that defines the application.
  • Build the Docker image.
  • Create a Kubernetes deployment manifest.
  • Deploy the application to a remote Kubernetes cluster.
  • Use Telepresence to connect to the application locally.
  • Make changes to the application and test them locally.

Creating the Dockerfile

The Dockerfile for our application will be very simple. It will only have one instruction:

FROM nginx:latest

Enter fullscreen mode Exit fullscreen mode

This will create a Docker image that is based on the nginx image.

Building the Docker Image

We can build the Docker image by running the following command:

docker build -t my-app .

Enter fullscreen mode Exit fullscreen mode

This will create a Docker image named my-app.

Creating the Kubernetes Deployment Manifest

The Kubernetes deployment manifest for our application will also be very simple. It will only have one line:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
      - name: my-app
        image: my-app
        ports:
        - containerPort: 80

Enter fullscreen mode Exit fullscreen mode

This will create a Kubernetes deployment that will run a single instance of our application. The application will be exposed on port 80.

Deploying the Application to a Remote Kubernetes Cluster

We can deploy the application to a remote Kubernetes cluster by running the following command:

kubectl apply -f deployment.yaml

Enter fullscreen mode Exit fullscreen mode

This will deploy the application to the default Kubernetes namespace.

Using Telepresence to Connect to the Application Locally

Once the application is deployed to the remote Kubernetes cluster, we can use Telepresence to connect to it locally. To do this, we will need to create a Telepresence configuration file. The Telepresence configuration file will specify the following:

  • The name of our application
  • The image of our application
  • The port of our application
  • The remote Kubernetes cluster

The Telepresence configuration file for our application will look like this:

apiVersion: telepresence.telepresence.io/v1alpha1
kind: Session
metadata:
  name: my-app
spec:
  container:
    image: my-app
    command: ["nginx", "-g", "daemon off;"]
    ports:
    - containerPort: 80
  remote:
    cluster: my-cluster

Enter fullscreen mode Exit fullscreen mode

We can start Telepresence by running the following command:

telepresence run my-app.telepresence.yaml

Enter fullscreen mode Exit fullscreen mode

This will start the traffic manager pod in the remote Kubernetes cluster and forward traffic to our local machine. We can then connect to the application as if it were running in the remote cluster.

Making Changes to the Application and Testing them Locally

Once we are connected to the application locally, we can make changes to the code and test them immediately. To do this, we can simply edit the Dockerfile or the Kubernetes deployment manifest and then rebuild the Docker image or deploy the application again.

Conclusion

Docker Telepresence is a great tool that can help you improve your Kubernetes development experience. By using Telepresence, you can develop and test your applications locally, while still having access to the resources of a remote Kubernetes cluster. This can save you time and improve your productivity.

I hope this blog post has helped you learn how to use Docker Telepresence. If you have any questions, please feel free to leave a comment below.

Discussion (0)