This tutorial provides a step by step guide to configure an Okteto Pipeline. Okteto Pipelines allow anyone on your team or your open source community to deploy a realistic environment for your application on Okteto Cloud in just one click.
The tutorial is composed of the following steps:
- Step 1: Code the Hello World application
- Step 2: Define a Dockerfile for building the Docker image of the Hello World application
- Step 3: Create Kubernetes manifests to deploy the Hello World application on Okteto Cloud
- Step 4: Automate the deployment of the Hello World application with an Okteto Pipeline
- Step 5: Deployment time!
Let's get started!
We will use a simple Hello World application to illustrate how to configure an Okteto Pipeline. The Hello World application is a simple web service that responds "Hello World!" to every request. It is written in Go, but Okteto can be used with any application that runs on Kubernetes.
First, make a new directory called
hello-world and move inside it:
Create a new file under the name
main.go with the following content:
main.go implements a Golang web server that listens on port 8080 and responds to every Http request with the message Hello world!
Next, initialize your go module running the following command:
You need to build a Docker image and push it to a Docker registry before Okteto Cloud can run your application.
To do that, you need to define a
Dockerfile file is a sequence of instructions to build the Docker image of your application.
If you're not familiar with Docker, we strongly recommend you learn about it.
Open a new file under the name
Dockerfile with the following content:
To deploy an application to Okteto Cloud, you need to define it using Kubernetes manifests.
Let's start by creating a new folder for the Kubernetes manifests:
When you use a Kubernetes manifest, you tell Kubernetes how you want your application to run. This time, you'll create a deployment object. Create a new file
k8s/deployment.yaml with the following content:
The deployment manifest has three main sections:
metadatadefines the name for your deployment.
replicasdefines how many copies of it you want running.
templatetells Kubernetes what to deploy, and what labels to add. In this case, a single container, with the
okteto.dev/hello-world:latestimage we will build in our Okteto Pipeline, listening on port 8080, and with the
app: hello-worldlabel. Note that this label is the same used in the
If you want to know more about Kubernetes deployment objects, check the official docs.
You'll now need a way to access your application. You can expose an application on Kubernetes by creating a service object. Create a new file called
k8s/service.yaml with the following content:
The service manifest has four main sections:
metadatatells Kubernetes how to name your service
typetells Kubernetes how you want to expose your service. In this case, it will expose it externally through a Load Balancer. In you want to expose your application using ingress, check the docs.
portstells Kubernetes which ports you want to expose
selectortells Kubernetes how to direct traffic. In this case, any pod with the
app: hello-worldlabel will receive traffic.
Kubernetes manifests can get complex to manage. As your application grows, we recommend you pack your application using Helm.
You now have everything ready to define the Okteto Pipeline of the Hello World application.
When writing your Kubernetes manifests, take into account the multitenant Kubernetes restrictions that we have in place to make Okteto Cloud a secure environment to run your applications.
You can automate the deployment of the Hello World application with an Okteto Pipeline to provide a one-click deployment experience for anyone in your team or your open source community.
To define your Okteto Pipeline, create a new file
okteto-pipeline.yml with the following content:
The Okteto Pipeline manifest has a
deploy section to define the sequence of commands to deploy the Hello World application.
The first command builds the Docker image of the Hello World application and pushes the image to the Okteto Registry. Note that
okteto.dev/hello-world:latestis expanded to the current user image space to make this instruction portable between namespaces.
The second command deploys the Hello World application using
kubectland the Kubernetes manifests you created on Step 2.
You can make use of tools such as
kustomize in your Okteto Pipeline.
Read the Okteto Pipeline documentation to learn more about the Okteto Pipeline yaml syntax, available tools, and environment variables that you can use as part of your Okteto Pipeline.
Log into Okteto Cloud. Click on the Deploy button on the top left of the Okteto Cloud dashboard and type the URL of your Git repository to deploy the Hello World application:
After a few seconds, your application will be ready. You can access the Hello World application by clicking its endpoint:
You can make the deployment experience even smoother by adding a Develop on Okteto button to the
README.mdfile of your Git repository.
Congratulations, you just configured your first Okteto Pipeline on Okteto Cloud 🚀.
We have covered how to deploy realistic environments for cloud-native applications in just one-click. The full source code used on this tutorial is available here.