Kubernetes app with Go and Redis
This sample application demonstrates how you can embed Namespace Kubernetes Previews into your development workflow. You can build, deploy and get a preview of your features in less than a minute.
-
Install
kustomize
$ go install sigs.k8s.io/kustomize/kustomize/v5@latest
-
Log in to your Namespace workspace
$ nsc login
-
Clone this repository
$ git clone https://github.com/namespacelabs/guestbook-go.git && cd guestbook-go
-
Docker build and push the Go application
$ nsc build . -n guestbook:v1 -p Pushed: nscr.io/01gr48y5j6qv4mgheyj4mchj76/guestbook:v4
-
Set the Docker image in the
kustomization.yaml
file$ kustomize edit set image guestbook=nscr.io/01gr48y5j6qv4mgheyj4mchj76/guestbook:v1
-
Create an ephemeral cluster for your isolated tests and preview
$ nsc create Created new ephemeral environment! ID: oabpalureod3g More at: https://cloud.namespace.so/01gr48y5j6qv4mgheyj4mchj76/cluster/oabpalureod3g
-
Extract the kubeconfig file to access the remote Kubernetes cluster
$ nsc kubeconfig write oabpalureod3g --output_to /tmp/kubeconfig.yaml && \ export KUBECONFIG=$(cat /tmp/kubeconfig.yaml)
-
Deploy the manifests to the cluster with
kustomize
$ kubectl apply -k . service/frontend created service/redis-master created service/redis-replica created deployment.apps/guestbook created deployment.apps/redis-master created deployment.apps/redis-replica created
-
(Optional) You can verify that pods and services are up and running
$ kubectl get pods,svc NAME READY STATUS RESTARTS AGE pod/guestbook-685577f476-qk594 1/1 Running 0 25m pod/guestbook-685577f476-pl8pw 1/1 Running 0 25m pod/redis-replica-5d5bb655db-w9m7v 1/1 Running 0 25m pod/redis-replica-5d5bb655db-l8vtz 1/1 Running 0 25m pod/redis-master-67dcb4f96f-rq7ch 1/1 Running 0 25m pod/guestbook-685577f476-bswp2 1/1 Running 0 25m NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/kubernetes ClusterIP 10.143.0.1 <none> 443/TCP 37m service/frontend LoadBalancer 10.143.145.119 10.0.1.1 3000:31970/TCP 25m service/redis-master ClusterIP 10.143.191.80 <none> 6379/TCP 25m service/redis-replica ClusterIP 10.143.114.185 <none> 6379/TCP 25m
-
Create a public authenticated preview for the
frontend
LoadBalancer service$ nsc expose kubernetes oabpalureod3g --namespace=default --service=frontend --name=frontend Exported port 3000 from default/frontend: https://frontend-oabpalureod3g.fra1.nscluster.cloud
-
Done! Now you can access the above URL and check out your changes. The same URL is also accessible by all your teammates that are part of your Namespace workspace.
The prominent Kubernetes tutorial heavily inspired the Guestbook application we used in this guide. Check their repository out!