Okteto gives you instant cloud environments to code and collaborate in your Kubernetes cluster. Write code using your favorite IDE, and see the results directly in the cloud. No commit 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.
You’ll use the CLI to create an account in Okteto, download your Kubernetes credentials, activate your namespaces and manage your Okteto Environments.
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
Using an existing Kubernetes cluster?
It is possible to use Okteto with an existing cluster. If you’re interested in that scenario, jump to step 4 of the guide.
okteto login command to create and initialize your Okteto account.
When you create an account in Okteto, a service account, namespace, and credentials will be automatically created for you in 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 to give you the best possible development experience.
Once the login process is completed, open your browser and go to https://cloud.okteto.com. you should now see your empty personal namespace, ready to create new resources.
Run the following command to activate your new personal namespace:
okteto namespacecommand lets you easily change your Kubernetes context. If no namespace is provided, the command will switch to your Okteto personal namespace.
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. Okteto 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.
Start your Okteto Environment by running the following command in your local terminal:
Deployment 'math' doesn't exist. Do you want to create a new one? [y/n]: y
okteto upcommand will automatically start an Okteto Environment. It will also start a file synchronization service to keep your changes up to date between your local filesystem and your Okteto Environment.
Once the Okteto Environment is ready, start your application by executing the following command in your Okteto Terminal:
go run main.go
You can now access the Math app at http://localhost/mult/3/4.
Congratulations, you just launched an Okteto Environment 🚀!
Now things get more exciting. Edit the file
main.go and switch the word
times at line 43. Save your changes. Cancel the execution of
go run main.go from your Okteto Terminal by pressing
ctrl + c. Run your tests to check that everything is fine with your changes:
go test ./...
And finally rerun your application:
go run main.go
Go back to the browser, and go to the new endpoint http://localhost:8080/times/3/4. 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:
kubectl delete -f manifests
deployment.apps "math" 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.