Last active
August 29, 2016 16:55
-
-
Save roicostas/0fbb9299f89eb0eba181d7c943056afe to your computer and use it in GitHub Desktop.
dockercoins in kubernetes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RAND_PORT=56789 | |
# Redirect registry url localhost:$RAND_PORT to kubernetes registry service | |
socat TCP-LISTEN:$RAND_PORT,fork TCP:$c1:$REGISTRY_PORT & | |
# Get dockercoins application and build | |
git clone https://github.com/roicostas/docker-orchestration | |
cd docker-orchestration/dockercoins | |
env REGISTRY_DASH=localhost:$RAND_PORT/ docker-compose -f docker-compose.yml-registry build | |
env REGISTRY_DASH=localhost:$RAND_PORT/ docker-compose -f docker-compose.yml-registry push | |
cd ../.. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Connect to the cluster | |
export KUBECONFIG="$PWD/kubeconfig" | |
kubectl config use-context vagrant-multi | |
# Get cluster info | |
kubectl cluster-info | |
# Get nodes | |
kubectl get nodes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Clone and configure | |
git clone https://github.com/roicostas/coreos-kubernetes.git | |
cd coreos-kubernetes/multi-node/vagrant | |
sed 's/#$worker_count=1/$worker_count=2/g' < config.rb.sample > config.rb | |
# Create cluster with vagrant | |
vagrant up | |
# Download kubernetes client | |
curl -O https://storage.googleapis.com/kubernetes-release/release/v1.3.4/bin/linux/amd64/kubectl > kubectl | |
chmod +x kubectl | |
export PATH=$PATH:$PWD | |
# Export node ips by name | |
for node in $(vagrant status | grep running | awk '{print $1}'); do | |
node_ip=$(vagrant ssh -c "ip address show eth1 | grep 'inet ' | sed -e 's/^.*inet //' -e 's/\/.*$//'" $node | tr -d '\r') | |
export $node=$node_ip | |
echo $node=$node_ip | |
done | |
#Allow to schedule containers in master node | |
kubectl uncordon $c1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kubectl run worker --image=$REGISTRY/dockercoins_worker | |
kubectl run redis --image=redis --expose --port=6379 | |
kubectl run rng --image=$REGISTRY/dockercoins_rng --expose --port=80 | |
kubectl run hasher --image=$REGISTRY/dockercoins_hasher --expose --port=80 | |
# Kubectl run does not support all configuration flags e.g target-port=container port | |
# Create webui deployment | |
kubectl run webui --image=$REGISTRY/dockercoins_webui --replicas=1 | |
# Create webui service, --type=NodePort exposes the service in a random public port | |
kubectl expose deployment webui --port=8000 --target-port=80 --name=webui --type=NodePort | |
# Get webui port | |
echo WEBUI_URL=$c1:$(kubectl describe service webui | grep NodePort | grep -o "[0-9]*") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get registry service description | |
wget https://raw.githubusercontent.com/roicostas/docker-orchestration/master/kubernetes/registry.yml | |
# Assign c1 a label to run the registry on it | |
kubectl label --overwrite node $c1 role=master | |
# Deploy application from file | |
kubectl create -f registry.yml | |
export REGISTRY_PORT=$(kubectl describe service kube-registry | grep NodePort | grep -o "[0-9]*") | |
export REGISTRY=localhost:$REGISTRY_PORT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Destroy cluster | |
vagrant -f destroy | |
# Kill port forwarding | |
pgrep socat | xargs kill |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get services, deployments or pods | |
kubectl get services | |
kubectl get deployments | |
kubectl get pods | |
# Get details of worker service | |
kubectl describe service worker | |
kubectl describe deployment worker | |
kubectl describe pod <pod-name> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vagrant halt -f w2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kubectl scale deployment worker --replicas=3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create new dockercoins_worker version, use port forwarding again to reach kubernetes registry | |
docker tag localhost:$RAND_PORT/dockercoins_worker localhost:$RAND_PORT/dockercoins_worker:v2 | |
docker push localhost:$RAND_PORT/dockercoins_worker:v2 | |
# Update worker image | |
kubectl set image deployment/worker worker=${REGISTRY}/dockercoins_worker:v2 | |
# Follow update state | |
kubectl rollout status deployment/worker |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment