{"id":19317775,"url":"https://github.com/queeniecplusplus/gke","last_synced_at":"2025-02-24T04:44:56.099Z","repository":{"id":104588261,"uuid":"309837757","full_name":"QueenieCplusplus/GKE","owner":"QueenieCplusplus","description":"vm, container, app, registry, cluster, pod, kubectl tool","archived":false,"fork":false,"pushed_at":"2020-11-18T03:15:40.000Z","size":167,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-06T04:26:01.104Z","etag":null,"topics":["kubectl-command","kubernetes","kubernetes-deployment"],"latest_commit_sha":null,"homepage":"https://github.com/QueenieCplusplus/QuickGoThru#gke","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/QueenieCplusplus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-11-04T00:09:11.000Z","updated_at":"2020-11-18T03:15:42.000Z","dependencies_parsed_at":null,"dependency_job_id":"0a1348e7-b015-4099-9c4d-dc6a05d0bdc9","html_url":"https://github.com/QueenieCplusplus/GKE","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/QueenieCplusplus%2FGKE","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/QueenieCplusplus%2FGKE/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/QueenieCplusplus%2FGKE/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/QueenieCplusplus%2FGKE/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/QueenieCplusplus","download_url":"https://codeload.github.com/QueenieCplusplus/GKE/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240420940,"owners_count":19798501,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["kubectl-command","kubernetes","kubernetes-deployment"],"created_at":"2024-11-10T01:16:14.485Z","updated_at":"2025-02-24T04:44:56.083Z","avatar_url":"https://github.com/QueenieCplusplus.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# GKE\nvm, container, app, registry, cluster, pod, kubectl tool\n\n![gke](https://cdn.qwiklabs.com/ZB%2FLTu%2FfOBuu7svaY0%2Fier%2FSvbJdfF3Lrb%2F5woXeecI%3D)\n\n\n# core steps:\n\n(1) create VM\n\n(2) create APP, pack app into Container Image\n\n ![container](https://miro.medium.com/max/1400/1*p6Nc3zVTadBSQDd7cXvzDw.png)\n\n(3) push Image to Container Registry\n\n(4) create GKE Cluster \n\n(5) create Pod (to include deployed containers)\n\n(6) allow External Traffic\n\n(7) scale up service\n\n(8) upgrade service\n\n\nstart from step 2:\n\n\u003e create a Nodejs Server \n\n* 2.1, in cloud shell, edit a js file\n\n        vi server.js\n        \n* 2.2, using editor\n\n        i\n        \n* 2.3, js file\n\n       var http = require('http');\n       \n       var reqHandler = function(req, res){\n       \n          res.writeHead(200);\n          res.end('hi');\n       \n       }\n       \n       var www = http.createServer(reqHandler);\n       www.listen(8080);\n\n* 2.4, esc the file and save it\n\n       ESC\n       \n       :wq\n       \n* 2.5, start server in shell\n\n       node server.js\n       \n* 2.6, see result of display in Browser\n\n      Use the built-in Web preview feature of Cloud Shell to open a new browser tab and proxy a request to the instance you just started on port 8080.\n      \n      \n    ![server](https://cdn.qwiklabs.com/a6YnJv8GlGae4rnJIbjA27J8c7YApa%2B6noPFkkKxZjk%3D)\n      \n      \n start from step 3:\n \n \u003e copy code file to container image\n \n   the docker file is to describe the image you want to build,\n   it can extend from the other existing image, such as above mentioned nodejs file.\n \n * 3.1, create Docker file image\n \n        vi Dockerfile\n        \n * 3.2, copy Node.js content to Docker file, press i firsly\n \n          FROM node:6.9.2\n          EXPOSE 8080\n          COPY server.js .\n          CMD node server.js\n          \n * 3.3, check project id\n \n        see connection detail in cloud console\n          \n * 3.4, build docker file and run it\n \n        docker built -t gcr.io/\u003cproject-id\u003e/\u003cnode name\u003e:v1\n        \n        docker run -d -p 8080:8080 gcr.io/\u003cproject-id\u003e/\u003cnode name\u003e:v1\n        \n * 3.5, check result in web-preview feature in gcloud shell or type following cmd line\n \n        curl http://localhost:8080\n        \n * 3.6, find container id\n \n         docker ps\n         \n         [output]\n         container id            image                               cmd\n         xxxxxxx          gcr.io/\u003cproject-id\u003e/\u003cnode name\u003e:v1        \"/bin/sh -c\"\n         \n * 3.7, push image to container registry\n \n         gcloud auth configure-docker\n         \n         docker push gcr.io/\u003cproject-id\u003e/\u003cimage name\u003e:v1\n         \n         \n         [output]\n         \n                The push refers to a repository [gcr.io/\u003cproj_id\u003e/\u003cnode_name\u003e]\n                ba6ca48af64e: Pushed\n                381c97ba7dc3: Pushed\n                604c78617f34: Pushed\n                fa18e5ffd316: Pushed\n                0a5e2b2ddeaa: Pushed\n                53c779688d06: Pushed\n                60a0858edcd5: Pushed\n                b6ca02dfe5e6: Pushed\n                v1: digest: sha256:8a9349a355c8e06a48a1e8906652b9259bba6d594097f115060acca8e3e941a2 size: 2002\n         \n * 3.8, go to gcr to check display info in cloud console.\n \n     ![gcr](https://cdn.qwiklabs.com/dQgWvGqTs5%2BVCSfmbpL2lpTlQ7dd19FwSIKTEBS3poA%3D)\n   \n start from step 4:\n \n \u003e create container's Cluster and Pod\n \n   A cluster consists of a master (api) server hosted by google, and a set of worker nodes which are VMs (gce).\n \n * 4.1, \n \n          gcloud config set project \u003cproj_id\u003e\n          \n * 4.2, create cluster with 2 nodes\n \n          gloud container cluster create \u003ccluster name\u003e\\\n          \n                --num-nodes 2\\\n                --machine-type \u003ctype\u003e\\\n                --zone \u003czone\u003e\n                \n           [output]\n           \n           Creating cluster hello-world...done.\n                Created [https://container.googleapis.com/v1/projects/PROJECT_ID/zones/us-central1-a/clusters/hello-kate].\n                kubeconfig entry generated for hello-world.\n                NAME         ZONE           MASTER_VERSION  MASTER_IP       MACHINE_TYPE   STATUS\n                hello-kate  us-central1-a  1.5.7           146.148.46.124  n1-standard-1  RUNNING\n \n * 4.3, check Navigation bar called GKE(kubernets Engine) in console\n \n \n   ![gke](https://cdn.qwiklabs.com/wMR0qhPxxgayDTSjDq1oXmoXEy4OeuQ%2FUtc6CZnvFT0%3D)\n        \n     \n start from step 5:\n\n\u003e create Pod\n\n   A pod consists of single/multiple containers tiled together for adm/network purpose.\n   \n   hereby, we use single container bult with above mentioned nodejs image (stored in GCR), which serves content on port 8080.\n   \n   when calling deployment, the pod running containers image is created then.\n   \n* 5.1, to do deployment to create a (single container) Pod using kubectl tool\n\n             kubectl create deployment \u003cdeployed container name\u003e\\\n               \n                   --image = gcr.io/\u003cproject-id\u003e/\u003cnode name\u003e:v1  \n\n             [output]\n             \n             deployment.apps/\u003ccontainer name\u003e created\n             \n* 5.2, to create and scale Pod (Replica) using kubectl tool\n\n            kubectl get deployments\n            \n            [output]\n            NAME         READY   UP-TO-DATE   AVAILABLE   AGE\n            \u003cdeployed container name\u003e   1/1     1            1           1m36s\n            \n            kebectl get pods\n            \n            [output]\n            NAME                         READY     STATUS    RESTARTS   AGE\n            hello-node-714049816-ztzrb   1/1       Running   0          6m\n            \n            // hello-node-714049816-ztzrb is a pod id and name\n            \n\n* 5.3 to check state of a cluster using kubectl tool\n\n           kubectl cluster info\n           \n           kubectl config view\n           \n           kubectl logd \u003cpod-name\u003e \n           // 可能如上為 \u003cdeployed container name\u003e 或是 hello-node-714049816-ztzrb\n           \n           \n * 5.4, to do trouble shoot\n \n            kubectl get events\n            \n# LB\n\nThe Kubernetes master creates the LB and related GCE VM (worker nodes) \nforwarding rules, target pools, and firewall rules to make the service fully accessible from outside of Google Cloud.\n\nstart from step 6:\n\n\u003e to allow External traffic.\n\nWithout this step, the pod's network flow is connect with its cluter in inernal network.\n\n* 6.1, to create a external ip for pod \n\n         kubectl expose deployment \u003cdeployed container name\u003e\n\n         kubectl expose deployment hello-node --type=\"LoadBalancer\" --port=8080\n         // this flag matters with LB:  \n         // This will cause the resulting service to LB traffic across all pods managed by the deployment (in this case only 1 pod, but you will add more replicas later).\n         \n         [output]\n         service/ \u003cdeployed container name\u003e exposed\n       \n * 6.2, to find public/private (accessible) IP addr of the services\n \n        kubectl get services\n        \n        [outputs]\n        NAME                        CLUSTER-IP     EXTERNAL-IP      PORT(S)    AGE\n        \u003cdeployed container name\u003e   10.3.250.149   104.154.90.147   8080/TCP   1m    // public accessible ouside cloud\n        kubernetes                  10.3.240.1     \u003cnone\u003e           443/TCP    5m    // visible only in cloud\n       \n  \n* 6.3, to check service is available to pubic by pointing browser to addr http://\u003cEXTERNAL_IP\u003e:8080\n\n      ![ip](https://cdn.qwiklabs.com/C36gw9A9wyqza3PveBYBCsMggISATH80A18fqFBck7U%3D)\n        \n# Scale Up\n\nstart from step 7:\n\n* 7.1, using RC to scale up App services\n\n      kubectl scale deployment \u003cdeployed container name\u003e --replicas=4\n      \n      [output]\n      deployment.extensions/\u003cdeployed container name\u003e scaled\n\n![scale](https://cdn.qwiklabs.com/xcK5q7mZsGBWS%2BPbytdmF0W%2BdsZxvNXdOIEPBXX13X4%3D)\n\n\n# Upgarde Service\n\n   once the developer modifies the code file, devops \u0026 SRE shall roll out the upgrade then.\n\nstart from step 8:\n\n* 8.1, build docker file and push it to GCR\n \n        docker built -t gcr.io/\u003cproject-id\u003e/\u003cnode name\u003e:v2\n        \n        docker push gcr.io/\u003cproject-id\u003e/\u003cnode name\u003e:v2\n        \n        \n* 8.2, to edit yaml file to change config, due to the changing deployed containers image.\n\n        // update the pod to new image\n        \n        ubectl edit deployment \u003cdeployed container name\u003e\n        \n        // Look for Spec \u003e containers \u003e image\n        \n        # Please edit the object below. Lines beginning with a '#' will be ignored,\n                # and an empty file will abort the edit. If an error occurs while saving this file will be\n                # reopened with the relevant failures.\n                #\n                apiVersion: extensions/v1beta1\n                kind: Deployment\n                metadata:\n                  annotations:\n                    deployment.kubernetes.io/revision: \"1\"\n                  creationTimestamp: 2016-03-24T17:55:28Z\n                  generation: 3\n                  labels:\n                    run: hello-node\n                  name: hello-node\n                  namespace: default\n                  resourceVersion: \"151017\"\n                  selfLink: /apis/extensions/v1beta1/namespaces/default/deployments/hello-node\n                  uid: 981fe302-f1e9-11e5-9a78-42010af00005\n                spec:\n                  replicas: 4\n                  selector:\n                    matchLabels:\n                      run: hello-node\n                  strategy:\n                    rollingUpdate:\n                      maxSurge: 1\n                      maxUnavailable: 1\n                    type: RollingUpdate\n                  template:\n                    metadata:\n                      creationTimestamp: null\n                      labels:\n                        run: hello-node\n                    spec:\n                      containers:\n                      - image: gcr.io/PROJECT_ID/hello-node:v1 ## Update this line ##\n                        imagePullPolicy: IfNotPresent\n                        name: hello-node\n                        ports:\n                        - containerPort: 8080\n                          protocol: TCP\n                        resources: {}\n                        terminationMessagePath: /dev/termination-log\n                      dnsPolicy: ClusterFirst\n                      restartPolicy: Always\n                      securityContext: {}\n                      terminationGracePeriodSeconds: 30\n                      \n * 8.3, to leave the editor\n \n         ESC\n \n         :wq\n\n        [output]\n        deployment.extensions/\u003cdeployed container name\u003e edited\n\n* 8.4, to run pod with new image by running again deplotment\n\n        // New pods will be created with the new image and the old pods will be deleted.\n        \n        kubectl get deployments\n        \n        [output]\n        NAME                    DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE\n        \u003cdeploy container name\u003e   4         4         4            4           1h\n\n# Ref\n\nhttps://kubernetes.io/docs/tutorials/kubernetes-basics/update/update-intro/\n\nhttps://cloud.google.com/solutions/prep-kubernetes-engine-for-prod\n\n\n# Ref code\n\n66(container), 11765(kafka), 11777(microservice)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqueeniecplusplus%2Fgke","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fqueeniecplusplus%2Fgke","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqueeniecplusplus%2Fgke/lists"}