Last active
March 23, 2016 19:44
-
-
Save mshustov/24638a3bd64b93b14340 to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
REL_PATH=$(dirname $0) | |
cd $REL_PATH | |
env=$1 | |
CONFIG=$(cat container-config/env-$env.sh | base64) | |
# delete the old config | |
sed -e "s/{{config_data}}/''/g" container-config/config-template.yaml | kubectl delete -f - | |
# create new one | |
sed -e "s/{{config_data}}/${CONFIG}/g" container-config/config-template.yaml | kubectl create -f - | |
#create service & replication controller | |
kubectl create -f kubectl-config-$env.yaml |
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
apiVersion: v1 | |
kind: Service | |
metadata: | |
name: balkan | |
labels: | |
name: balkan | |
spec: | |
type: LoadBalancer | |
loadBalancerIP: 0.0.0.0 | |
# static IP allocated in the Google Cloud | |
ports: | |
- name: http | |
port: 80 #порт на котором будет слушать сервис | |
targetPort: 8000 #порт контейнера на который будет производиться трансляция запросов | |
protocol: TCP | |
selector: | |
name: balkan # поле должно совпадать с аналогичным в конфиге ReplicationController | |
--- | |
apiVersion: v1 | |
kind: ReplicationController | |
metadata: | |
labels: | |
name: balkan | |
name: balkan #controller | |
spec: | |
replicas: 2 | |
selector: | |
name: balkan | |
template: | |
metadata: | |
labels: | |
name: balkan | |
spec: | |
containers: | |
- image: eu.gcr.io/${PROJECT_ID}/${CONTAINER_NAME}:v3 # format just for example! | |
name: balkan | |
command: [ "/bin/bash", "-c"] | |
args: ["source /etc/configs; cd folder; node server.js"] | |
ports: | |
- containerPort: 8000 | |
volumeMounts: | |
- name: secret-name | |
mountPath: /etc/configs | |
readOnly: true | |
volumes: | |
- name: secret-name | |
secret: | |
secretName: secret-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
export PROJECT=balkan | |
export PROJECT_ID=balkan-id (get ID on page) ?? | |
export CLUSTER_NAME=bon | |
export CONTAINER_NAME=balkan-container | |
gcloud config set compute/region europe-west1 | |
gcloud config set compute/zone europe-west1-b | |
gcloud config set project $PROJECT | |
gcloud config set container/cluster $CLUSTER_NAME | |
gcloud config list | |
# with CPU=1 rolling-update failed | |
gcloud container clusters create $CLUSTER_NAME --num-nodes 1 --machine-type n1-standard-2 | |
#with manual versioning | |
docker build -t eu.gcr.io/${PROJECT_ID}/${CONTAINER_NAME}:v2 . ; gcloud docker push eu.gcr.io/${PROJECT_ID}/${CONTAINER_NAME}:v2 | |
kubectl create -f kubectl-config.yaml | |
#to push new image: | |
docker build -t eu.gcr.io/${PROJECT_ID}/${CONTAINER_NAME}:v3 . ; gcloud docker push eu.gcr.io/${PROJECT_ID}/${CONTAINER_NAME}:v3 | |
#switch to new version: balkan is controller name from kuberctl-config.yaml | |
kubectl rolling-update balkan --image=eu.gcr.io/${PROJECT_ID}/${CONTAINER_NAME}:v3 | |
#to check everything is fine: | |
kubectl describe pods | |
kubectl get services # get actual external ip, check with request | |
kubectl get rc # get image version |
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
apiVersion: v1 | |
kind: Secret | |
metadata: | |
name: balkan-config | |
type: Opaque | |
data: | |
config: {{config_data}} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment