Okteto keeps your local development workflow untouched, but magically integrated in your Kubernetes cluster. Write code using your favorite IDE, and see the results directly in the cloud. No commit, build or push required.
This example shows how to leverage Okteto to develop a Go application directly in a Kubernetes cluster. It will be deployed using raw Kubernetes manifests.
The Okteto CLI transforms your remote Kubernetes pods into development environments with all your dev tools available to build and test your applications. It also starts a bidirectional synchronization service between your local filesystem and your remote containers to avoid the build/push/redeploy cycle. See your changes live in the cloud in seconds!
The Okteto CLI is open source, and the code is available here. Feel free to check it out, contribute, and please, star it 🤗!
Install the Okteto CLI by running the following command in your local terminal:
curl https://get.okteto.com -sSfL | sh
wget https://downloads.okteto.com/cli/okteto-Windows-x86_64 -OutFile c:\windows\system32\okteto.exe
The Okteto CLI works in any Kubernetes cluster. If you are interested in using your existing Kubernetes cluster, jump to step 4 of the guide. However, the Okteto CLI is deeper integrated with Okteto Cloud, the hosted version of Okteto Enterprise. Check all the features provided by Okteto Cloud here.
okteto login command to create and initialize your Okteto account.
When you create an Okteto Cloud account, a service account, namespace, and credentials will be automatically created for you in the Okteto’s multi-tenant kubernetes cluster. These resources are configured automatically to include network policies, quotas, pod security policies, admission webhooks, roles, role bindings and limit ranges. This way, every developer has access to the Kubernetes cluster without interfering with other developer namespaces.
Run the following command to activate your personal namespace:
okteto namespace command downloads your Kubernetes credentials from Okteto Cloud, adds them to your kubeconfig file, and sets it as the current context. Once you do this, you will have full access to your Kubernetes namespace with any Kubernetes tool.
Get a local version of the Golang Sample App by executing the following commands in your local terminal:
git clone https://github.com/okteto/samples
manifest/ directory you also have raw Kubernetes manifests that we will use in this guide to deploy the application in the cluster. The Okteto CLI works however independently of your common deployment practices or tools.
If you don’t have
kubectlinstalled, follow this guide.
Run the Golang Sample App by executing:
kubectl apply -f manifests
You now have a functioning git repository that contains a simple Go application and your application deployed in the cluster. Notice that since you’ll be working directly on a remote environment, you don’t need to have Go, nor Docker in your machine to run your application.
Transform your application pods into a development environment by running the following command:
✓ Okteto Environment activated
okteto up command will automatically start an Okteto Environment, which means:
okteto/hello-world:golang-dev. This image contains the required dev tools to build, test and run the Golang Sample App.
Once the Okteto Environment is ready, start your application by executing the following command in your Okteto Terminal:
go run main.go
Your application is now ready. Open your browser and go the URL of the application. You can get the URL by logging into Okteto Cloud and clicking in the application’s endpoint.
Congratulations, you just launched an Okteto Environment 🚀!
Now things get more exciting. Edit the file
main.go and replace the word
Okteto Cloud on line 23. Save your changes.
Cancel the execution of
go run main.go from your Okteto Terminal by pressing
ctrl + c. Now rerun your application:
go run main.go
Go back to the browser and reload the page. Notice how your changes are instantly applied. No commit, build or push required 😎!
okteto up command by pressing
Ctrl + C +
exit and run the following commands to remove the resources created by this guide:
okteto down -v
✓ Okteto Environment deactivated
kubectl delete -f manifests
deployment.apps "hello-world" deleted
You now know how easy you can do efficient development in the cloud.
okteto.yml file in the sample folder. Okteto uses that manifest to determine the name of your Okteto Environment, the docker image to use and where to upload your code. Check the Okteto manifest docs to customize your Okteto Environments with your own dev tools, images and dependencies.