This an Hello World example application using Go and etcd.
Start the environment defined in the compose.yml file and leave it running in foreground:
docker compose up --buildExecute the following commands in another shell.
Show the running containers:
docker compose psTry 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 fooInvoke the hello endpoint:
wget -qO- http://localhost:8888At 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 --timeout=0NB 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 scDeploy the manifest:
kubectl apply -f manifest.ymlWait 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-0Display the Ingress, Service, Pod, PersistentVolumeClaim,
PersistentVolume, and StorageClass resources:
kubectl get service,pod,pvc,pv,scAccess 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 1Delete 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.ymlVerify that the PersistentVolumeClaim and PersistentVolume resources are
still available:
kubectl get pvc,pvRecreate 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,scAccess 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 1Notice 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- Dockerfile Reference
- Compose Spec
- OCI Image Format
- Pre-Defined Annotation Keys (used in the Dockerfile
LABELinstructions)
- Pre-Defined Annotation Keys (used in the Dockerfile
- Kubernetes