Deploy App Manually
- Process
-
- Build images for our app
- Tag images so that they are named $REGISTRY/servicename
- Upload these images to a registry
- Create deployments using these images
- Expose (with a ClusterIP) these deployments so they can communicate with each other
- Expose (with a NodePort) the web UI so we can access it from outside
Deploying a self-hosted registry¶
Create the registry service:
kubectl run registry --image=registry:2
Expose it on a NodePort:
kubectl expose deploy/registry --port=5000 --type=NodePort
Connect to registry:
MINIKUBE_IP=$(minikube ip) # or 127.0.0.1 if main node
kubectl describe svc/registry
NODEPORT=$(kubectl get svc/registry -o json | jq .spec.ports[0].nodePort)
REGISTRY=$MINIKUBE_IP:$NODEPORT
curl $REGISTRY/v2/_catalog
Push image to registry:
docker pull busybox
docker tag busybox $REGISTRY/busybox
docker push $REGISTRY/busybox
Building and pushing images¶
Build and push image:
$ cat docker-compose.yml
version: "3"
services:
rng:
build: dockercoins/rng
image: ${REGISTRY-127.0.0.1:5000}/rng:${TAG-latest}
deploy:
mode: global
hasher:
build: dockercoins/hasher
image: ${REGISTRY-127.0.0.1:5000}/hasher:${TAG-latest}
webui:
build: dockercoins/webui
image: ${REGISTRY-127.0.0.1:5000}/webui:${TAG-latest}
ports:
- "8000:80"
redis:
image: redis
worker:
build: dockercoins/worker
image: ${REGISTRY-127.0.0.1:5000}/worker:${TAG-latest}
deploy:
replicas: 10
export REGISTRY
export TAG=v0.1
docker-compose build
docker-compose push
Deploy:
kubectl run redis --image=redis
for SERVICE in hasher rng webui worker; do
kubectl run $SERVICE --image=$REGISTRY/$SERVICE:$TAG
done
Exposing services internally¶
What to expose:
- 3 deployments need to be reachable by others: hasher, redis, rng
- worker doesn't need to be exposed
- webui will be dealt with later
Expose deployments:
kubectl expose deployment redis --port 6379
kubectl expose deployment rng --port 80
kubectl expose deployment hasher --port 80
Stream the worker's logs:
kubectl logs deploy/worker --follow
Exposing services for external access¶
What to expose:
- We want to access the Web UI
- We will expose it with a NodePort (just like we did for the registry)
Create a NodePort service for the Web UI:
kubectl expose deploy/webui --type=NodePort --port=80
Check that the port was allocated:
kubectl get svc
Accessing the Web UI:
- We can now connect to any node, on the allocated node port, to view the web UI
- http://node-ip-address:3xxxx/