Deploy Go applications on k8s via Minikube
In this post we will learn how to deploy two different Go applications on kubernetes and use them outside cluster via minikube
Pre-requisite
- Minikube cluster
- Docker
- 2 different Go applications
- Kubectl
How to start minikube cluster ?
First of all create a virtual machine names as sample-docker-machine.
docker-machine create --driver virtualbox sample-docker-machine
Then get the IP address of this docker machine
docker-machine ip sample-docker-machine
Now we use this IP address to start the minikube cluster .
minikube start --vm-driver="virtualbox" --insecure-registry="<docker-machine ip address>":80
In this way our minikube cluster is started.
Create Go Applications
Lets create 2 different Go application.
- start-repo
- go-docker
Lets discuss first about start-repo
create one main file names as main.go
package mainimport (
"encoding/json"
"log"
"net/http" "github.com/gorilla/mux"
)type Person struct {
ID string `json:"id,omitempty"`
Firstname string `json:"firstname,omitempty"`
}func GetPong(w http.ResponseWriter, req *http.Request) {
abc := Person{ID : "123",}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(abc)
}func main() {
router := mux.NewRouter()
router.HandleFunc("/", GetPong).Methods("GET")
log.Fatal(http.ListenAndServe(":8080", router))
}