Git Product home page Git Product logo

okteto-go-starter's Introduction

Okteto Golang Starter

The purpose of this repo is to provide required files to directly develop Golang Web API on Kubernetes with Okteto tool.

Requirements

  • Latest Okteto binary installed on your machine
  • An operational Kubernetes or k3s cluster
  • An Ingress Controller in your cluster (nginx in my case)
  • A StorageClass to automaticaly create pv with pvc object. Your StorageClass should be set as default with this command:
kubectl patch storageclass MY-STORAGECLASS -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'

I personnaly use cert-manager and HashiCorp Vault to get a valid TLS certificate for my subdomain. If you don't use these tools you need to rewrite backend-ing.yml in manifests directory to work with letsencrypt or http (no tls).
These documentations can help you:

First Usage

If it's the first time you use okteto and this repo you just need to do these commands:

git clone https://github.com/aamoyel/okteto-go-starter.git
kubectl apply -f manifests
okteto up

When you call 'okteto up' for the first time you need to select a kubernetes context.

Air Binary

You need to have Air binary to automatically build and run your go project. Your can find Air installation instructions down below.
After 'okteto up' (in dev container), run this command :

curl -sSfL https://raw.githubusercontent.com/cosmtrek/air/master/install.sh | sh -s -- -b $(go env GOPATH)/bin

After this, simply type 'air' in your terminal

Results

Go to http://localhost:8080 to see local development container process and at your ingress url, https://dev.amoyel.loc in my case.
You can change domain and subdomain in backend-cert.yml file in manifests directory.

End Dev Session:

Simply enter CTRL+C to stop air binary.
Then do CTRL+D or type 'exit'.
And finaly type 'okteto down' to avoid resources consumption.

Common usage

okteto up
air

Develop your Golang API ...
Do this step when you want to stop your dev session.

Change Golang Version

If you want to change Go version, simply change:

  • Image tag in okteto.yml, eg: "image: golang:1.18.5-bullseye"
  • Image tag in manifests/backend-deploy.yml, eg: "- image: golang:1.18.5-bullseye"

You can find other tags directly on Docker Hub.

More Info

To find more information on okteto.yml and okteto cli go to https://www.okteto.com/docs/reference/cli/

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.