Giter Club home page Giter Club logo

hello-etcd's Introduction

About

Build

This an Hello World example application using Go and etcd.

Docker Compose Usage

Start the environment defined in the compose.yml file and leave it running in foreground:

docker compose up --build

Execute the following commands in another shell.

Show the running containers:

docker compose ps

Try executing commands inside the containers:

docker compose exec -T hello hello --version
docker compose exec -T etcd etcd --version
docker compose exec -T etcd etcdctl version
docker compose exec -T etcd etcdctl endpoint health
docker compose exec -T etcd etcdctl member list
docker compose exec -T etcd etcdctl put foo bar
docker compose exec -T etcd etcdctl get foo

Invoke the hello endpoint:

wget -qO- http://localhost:8888

At the first shell, stop the environment by pressing Ctrl+C, then start it again. Back at the second shell, redo the test, and notice that the hello counter resumes where it was left off due to etcd using a persistent volume.

Destroy the environment, including the persistent volumes:

docker compose down --volumes

Kubernetes Usage

NB This assumes you are using a Kind Kubernetes cluster as configured in rgl/my-ubuntu-ansible-playbooks. So YMMV.

Ensure that your Kubernetes cluster has support for persistent data. For that, display the available StorageClass, and ensure that is has a standard class, otherwise you have to modify the manifest.yml file to use a class that exists in your particular cluster:

kubectl get sc

Deploy the manifest:

kubectl apply -f manifest.yml

Wait for the deployments to finish, and PersistentVolumeClaim to be bound:

kubectl rollout status deployment hello-etcd
kubectl rollout status statefulset hello-etcd-etcd
kubectl wait --for jsonpath='{.status.phase}=Bound' pvc/etcd-data-hello-etcd-etcd-0

Display the Ingress, Service, Pod, PersistentVolumeClaim, PersistentVolume, and StorageClass resources:

kubectl get service,pod,pvc,pv,sc

Access the hello-etcd service from a kubectl port-forward local port:

kubectl port-forward service/hello-etcd 6789:web &
sleep 3
wget -qO- http://localhost:6789 # Hello World #1!
wget -qO- http://localhost:6789 # Hello World #2!
wget -qO- http://localhost:6789 # Hello World #3!
kill %1
sleep 1

Delete the resources:

NB Since we are using a StatefulSet with persistentVolumeClaimRetentionPolicy set to Retain (the default), the PersistentVolumeClaim and PersistentVolume resources are not automatically deleted.

kubectl delete -f manifest.yml

Verify that the PersistentVolumeClaim and PersistentVolume resources are still available:

kubectl get pvc,pv

Recreate the resources:

kubectl apply -f manifest.yml
kubectl rollout status deployment hello-etcd
kubectl rollout status statefulset hello-etcd-etcd
kubectl get service,statefulset,pod,pvc,pv,sc

Access the hello-etcd service from a kubectl port-forward local port:

kubectl port-forward service/hello-etcd 6789:web &
sleep 3
wget -qO- http://localhost:6789 # Hello World #4!
wget -qO- http://localhost:6789 # Hello World #5!
wget -qO- http://localhost:6789 # Hello World #6!
kill %1
sleep 1

Notice that the hello counter resumes where it was left off due to etcd using a persistent volume.

Delete everything, including the persistent volume:

kubectl delete -f manifest.yml
kubectl delete persistentvolumeclaim/etcd-data-hello-etcd-etcd-0
kubectl get service,pod,pvc,pv,sc

References

hello-etcd's People

Contributors

rgl avatar

Watchers

 avatar  avatar

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.