GithubHelp home page GithubHelp logo

lapazcloud / sample-app Goto Github PK

View Code? Open in Web Editor NEW
0.0 4.0 0.0 33 KB

Sample app to run on Kubernetes

Dockerfile 7.19% JavaScript 19.74% HTML 32.86% Smarty 40.21%
google-cloud kubernetes k8s aprender nube kubectl bolivia

sample-app's Introduction

Sample app to run on Kubernetes

Building and running on Docker

docker build -t sample-app:v1 .
docker run --name sample-app -p 3000:3000 -d sample-app:v1

Uploading to Google Cloud Container Registry

gcloud auth configure-docker
docker tag sample-app:v1 gcr.io/*REPLACE_WITH_YOUR_NAME*/sample-app:v1
docker push gcr.io/*REPLACE_WITH_YOUR_NAME*/sample-app:v1
gcloud container images list
gcloud container images list-tags gcr.io/*REPLACE_WITH_YOUR_NAME*/sample-app

Creating a Kubernetes cluster

gcloud container clusters create *REPLACE_WITH_YOUR_NAME*
gcloud container clusters get-credentials *REPLACE_WITH_YOUR_NAME*
kubectl get nodes
kubectl get pods
kubectl get pods --all-namespaces
kubectl proxy --port=8080

Open http://localhost:8080/ on your browser.

Imperative deployments

Deploying the sample app

kubectl run sample-app \
--image gcr.io/*REPLACE_WITH_YOUR_NAME*/sample-app:v1 \
--port 3000

kubectl get pods
kubectl get deployments

kubectl expose deployment sample-app \
--type LoadBalancer \
--port 80 \
--target-port 3000

kubectl get service sample-app

Visit http://EXTERNAL-IP/ on your browser.

Scaling the sample app

kubectl scale deployment/sample-app \
--replicas 10

kubectl get pods -o wide

kubectl logs -f deployment/sample-app

Updating the sample app

# Edit line 10 on views/index.pug with the following:
section.hero.is-fullheight.has-background-warning

docker build -t gcr.io/*REPLACE_WITH_YOUR_NAME*/sample-app:v2 .
docker push gcr.io/*REPLACE_WITH_YOUR_NAME*/sample-app:v2
gcloud container images list-tags gcr.io/*REPLACE_WITH_YOUR_NAME*/sample-app

kubectl set image deployment/sample-app \
sample-app=gcr.io/*REPLACE_WITH_YOUR_NAME*/sample-app:v2

kubectl get pods -w

Visit http://EXTERNAL-IP/ periodically to get the update.

Declarative deployments

Exporting the current app

mkdir kubernetes
cd kubernetes
kubectl get deployment/sample-app --export -o yaml > sample-app-deployment.yaml
kubectl get service/sample-app --export -o yaml > sample-app-service.yaml

Rolling back and scaling down

# Edit sample-app-deployment.yaml
# Line 14:
replicas: 5
# Line 31:
- image: gcr.io/*REPLACE_WITH_YOUR_NAME*/sample-app:v1

# Perform the update
kubectl replace -f sample-app-deployment.yaml

Delete the deployment

kubectl delete -f sample-app-deployment.yaml
kubectl get pods -o wide

Then wait for all pods to be removed from Kubernetes.

Failing health and readyness checks

# Add the checks after line 33 on sample-app-deployment.yaml:
readinessProbe:
    httpGet:
    path: /readyZZZ
    port: 3000
livenessProbe:
    httpGet:
    path: /healthZZZ
    port: 3000

kubectl create -f sample-app-deployment.yaml
kubectl get pods -o wide

Visit http://EXTERNAL-IP/ to get an error, showing the checks are in place.

Fixing the healthcheck and readyness probes

# Remove the ZZZ letters from the checks on sample-app-deployment.yaml:
readinessProbe:
    httpGet:
    path: /ready
    port: 3000
livenessProbe:
    httpGet:
    path: /health
    port: 3000

kubectl replace -f sample-app-deployment.yaml
kubectl get pods -o wide

Visit http://EXTERNAL-IP/ to visit the site.

Cleaning up resources

Delete the app

kubectl delete -f sample-app-service.yaml
kubectl delete -f sample-app-deployment.yaml

Delete the container images

gcloud container images delete gcr.io/*REPLACE_WITH_YOUR_NAME*/sample-app:v1
gcloud container images delete gcr.io/*REPLACE_WITH_YOUR_NAME*/sample-app:v2

Delete the Kubernetes cluster

gcloud container clusters delete *REPLACE_WITH_YOUR_NAME*

sample-app's People

Contributors

darvein avatar yamilurbina avatar

Watchers

 avatar  avatar  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.