Git Product home page Git Product logo

devops-task's Introduction

Devops-task

a small devops task which includes developing simple api and deploying the task on gcp using kubernetes

Instructions

This is a basic Spring boot project. In order to launch the api, you should take the following steps:

  1. perform the gradle command and package java program:
    ./gradlew build

  2. build docker image:
    docker build -f Dockerfile -t test-docker .

  3. modify docker tag:
    docker tag test-docker gcr.io/java-dev-kubernetes/test-docker

  4. push the image to the gcr. (note that we should login to gcr in advance, gcloud auth configure-docker)
    docker push gcr.io/java-dev-kubernetes/test-docker

  5. create the kubernetes cluster on gcp using
    gcloud container clusters create test-demo --zone=asia-east1-b --cluster-version=1.10.5-gke.0

  6. create the node-pool on clusters
    gcloud container node-pools create pool-1 --cluster=test-demo --machine-type=n1-standard-1 --num-nodes=2
    --service-account='[email protected]' --node-version=1.10.5-gke.0 --node-labels='type=first' --tags=shuliu

  7. deploy all the files inside the k8s folder
    kubectl apply -f rolebinding.yaml
    kubectl apply -f test-service.yaml
    kubectl apply -f test-ingress.yaml
    kubectl apply -f test-deployment.yaml
    kubectl apply -f test-autoscaler.yaml

  8. after waiting a couple of minutes, we can get the external ip by performing the command:
    kubectl get ing
    so we know the external ip is 35.241.58.191

  9. finally, we can query the api:

    9.1 query api: http://35.241.58.191/

    I will inform you of querying the api ./nxchallenge/astarisborn

    9.2 query api: http://35.241.58.191/nxchallenge/astarisborn/

    I will show the general response of Hello world.

    9.3 query api: http://35.241.58.191/about

    I will show the signal saying that you are lost, please query ./nxchallenge/astarisborn.

    9.4 regarding identity management, we would assign specific token to user. So next time when uses access the api as well as his token, I will show Hello world as well as the map coordinates of where the pod ip is hosted.

    for example, the secret for the use is "newtonx-challenge", then the processed token would be "bmV3dG9ueC1jaGFsbGVuZ2VuZXd0b254LXBhZGRpbmc="

    so when user access the api: http://35.241.58.191/nxchallenge/astarisborn/bmV3dG9ueC1jaGFsbGVuZ2VuZXd0b254LXBhZGRpbmc=

    I will show the information like follows:

    "response":"Hello World"
    
    "myHostIP":"104.199.129.66"
    "latitude":"39.0438"
    "longitude":"-77.4874"
    

Some points that need to explain:

Deployment:

  1. scalability
    leverage HorizontalPodAutoscaler in kubernetes to adjust the number of pods dynamically. use cpu and memory as metrics to determine whether we need to scale out.

  2. health check
    develop the api /healthz to perform the health check

  3. pod antiaffinity
    prevent two pods from scattering within the same node, which increase the performance and efficiency.

Development:

  1. podIp and nodeIp
    If you want to get the private address of pod ip or node ip, we can expose pod information to containers via fieldRef through environment variables. In this case, because we want the map coordinates of host, so it is easy to get current external ip of node, and call the api to get the coordinates.

  2. identity management
    Frankly speaking, I'm not familiar with IDM or related professional IDM framework or service from like okta or mulesoft. Basically, I know it would be straightforward and easy to calculating some token the first time user access the api, and storing the token in the database. But in this case, to make it simple, I just calculate the token and compare the token everytime user access the api. Specifically, I will use our confidential algorithm to calculate the token which would be assigned to users. So the next time, the customer can use this token to identify himself and append to the original api to get some extra information.

devops-task's People

Contributors

sliu2200899 avatar

Watchers

James Cloos 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.