k8s – google 產生 node 方式

google 產生 node 方式

google 產生 node 方式

  1. 產生 node 機器(共三台),到 gcp (kubernetes engine) → 新增節點集區→ 填名稱→節點調整為 1 → 調整 cpu x2 ram 4G → 管理 關閉啟用自動升級功能/以及啟用自動修復功能

  2. 到 devops-k8s-prod/geo1~x/底下編輯 deploy.yml and service.yml
    deploy.yml 修改  
    有關 name: geo1 (要改的名稱) and nodeSelector: geo-slave-node-1 對應

    <span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr">apiVersion:</span></span></span></span></span></span></span></span> <span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string">extensions/v1beta1</span></span></span></span></span></span></span></span>
    <span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr">kind:</span></span></span></span></span></span></span></span> <span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string">Deployment</span></span></span></span></span></span></span></span>
    <span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr">metadata:</span></span></span></span></span></span></span></span>
    <span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr">  name:</span></span></span></span></span></span></span></span> <span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string">geo1</span></span></span></span></span></span></span></span>
    <span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr">spec:</span></span></span></span></span></span></span></span>
    <span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr">  replicas:</span></span></span></span></span></span></span></span> <span class="hljs-number"><span class="hljs-number"><span class="hljs-number"><span class="hljs-number"><span class="hljs-number"><span class="hljs-number"><span class="hljs-number"><span class="hljs-number">1</span></span></span></span></span></span></span></span>
    <span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr">  strategy:</span></span></span></span></span></span></span></span>
    <span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr">    type:</span></span></span></span></span></span></span></span> <span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string">RollingUpdate</span></span></span></span></span></span></span></span>
    <span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr">    rollingUpdate:</span></span></span></span></span></span></span></span>
    <span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr">      maxSurge:</span></span></span></span></span></span></span></span> <span class="hljs-number"><span class="hljs-number"><span class="hljs-number"><span class="hljs-number"><span class="hljs-number"><span class="hljs-number"><span class="hljs-number"><span class="hljs-number">1</span></span></span></span></span></span></span></span>
    <span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr">      maxUnavailable:</span></span></span></span></span></span></span></span> <span class="hljs-number"><span class="hljs-number"><span class="hljs-number"><span class="hljs-number"><span class="hljs-number"><span class="hljs-number"><span class="hljs-number"><span class="hljs-number">1</span></span></span></span></span></span></span></span>
    <span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr">  minReadySeconds:</span></span></span></span></span></span></span></span> <span class="hljs-number"><span class="hljs-number"><span class="hljs-number"><span class="hljs-number"><span class="hljs-number"><span class="hljs-number"><span class="hljs-number"><span class="hljs-number">5</span></span></span></span></span></span></span></span>
    <span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr">  template:</span></span></span></span></span></span></span></span>
    <span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr">    metadata:</span></span></span></span></span></span></span></span>
    <span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr">      labels:</span></span></span></span></span></span></span></span>
    <span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr">        name:</span></span></span></span></span></span></span></span> <span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string">geo1</span></span></span></span></span></span></span></span>
    <span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr">        env:</span></span></span></span></span></span></span></span> <span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string">production</span></span></span></span></span></span></span></span>
    <span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr">        color:</span></span></span></span></span></span></span></span> <span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string">blue</span></span></span></span></span></span></span></span>
    <span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr">    spec:</span></span></span></span></span></span></span></span>
    <span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr">      hostNetwork:</span></span></span></span></span></span></span></span> <span class="hljs-literal"><span class="hljs-literal"><span class="hljs-literal"><span class="hljs-literal"><span class="hljs-literal"><span class="hljs-literal"><span class="hljs-literal"><span class="hljs-literal">false</span></span></span></span></span></span></span></span>
    <span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr">      nodeSelector:</span></span></span></span></span></span></span></span>
            <span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string">cloud.google.com/gke-nodepool:</span></span></span></span></span></span></span></span> <span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string">geo-slave-node-1</span></span></span></span></span></span></span></span>
    <span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr">      containers:</span></span></span></span></span></span></span></span>
    <span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr">      - name:</span></span></span></span></span></span></span></span> <span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string">geo1</span></span></span></span></span></span></span></span>
    <span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr">        image:</span></span></span></span></span></span></span></span> <span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string">asia.gcr.io/-174006/geo:v0.6.1</span></span></span></span></span></span></span></span>
    <span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr">        imagePullPolicy:</span></span></span></span></span></span></span></span> <span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string">Always</span></span></span></span></span></span></span></span>
    <span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr">        ports:</span></span></span></span></span></span></span></span>
    <span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr">        - containerPort:</span></span></span></span></span></span></span></span> <span class="hljs-number"><span class="hljs-number"><span class="hljs-number"><span class="hljs-number"><span class="hljs-number"><span class="hljs-number"><span class="hljs-number"><span class="hljs-number">8106</span></span></span></span></span></span></span></span>
  3. 修改完執行 kubectl apply -f deploy.yml 。請看 pod 是否正常
    kubectl get pod | grep geo (deploy.yml)
    geo-b8d87f6dd-fktwr                          1/1     Running       0          18d
    geo-blue-74ffc77f69-vj8gl                    1/1     Running       0          17d
    geo1-78754b7f8b-tzbkg                        1/1     Running       0          174m
    geo2-5d6f8d8cc5-m698v                        1/1     Running       0          25m
    geo3-7ccf7594bd-vzd79                        1/1     Running       0          25m
    geo4-555f974fdf-lscmt                        1/1     Running       0          156
  4. service.yml 修改
    有關 name: geo1 (要改的名稱)
    <span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr">apiVersion:</span></span></span></span></span> <span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string">v1</span></span></span></span></span>
    <span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr">kind:</span></span></span></span></span> <span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string">Service</span></span></span></span></span>
    <span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr">metadata:</span></span></span></span></span>
    <span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr">  name:</span></span></span></span></span> <span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string">geo1</span></span></span></span></span>
    <span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr">spec:</span></span></span></span></span>
    <span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr">  type:</span></span></span></span></span> <span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string">NodePort</span></span></span></span></span>
    <span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr">  ports:</span></span></span></span></span>
    <span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr">    - name:</span></span></span></span></span> <span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string">geo1</span></span></span></span></span>
    <span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr">      protocol:</span></span></span></span></span> <span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string">TCP</span></span></span></span></span>
    <span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr">      port:</span></span></span></span></span> <span class="hljs-number"><span class="hljs-number"><span class="hljs-number"><span class="hljs-number"><span class="hljs-number">8106</span></span></span></span></span>
    <span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr">      targetPort:</span></span></span></span></span> <span class="hljs-number"><span class="hljs-number"><span class="hljs-number"><span class="hljs-number"><span class="hljs-number">8106</span></span></span></span></span>
    <span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr">  selector:</span></span></span></span></span>
    <span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr">    name:</span></span></span></span></span> <span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string">geo1</span></span></span></span></span>
    <span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr">    env:</span></span></span></span></span> <span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string">production</span></span></span></span></span>
    <span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr">    color:</span></span></span></span></span> <span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string">blue</span></span></span></span></span>
  5. 修改完執行 kubectl apply -f service.yml 。請看 pod 是否正常
    kubectl get service | grep geo
    geo                   NodePort       10.23.241.223               8106:31422/TCP                                 622d
    geo-blue              NodePort       10.23.253.176               8106:31244/TCP                                 31d
    geo1                  NodePort       10.23.246.55                8106:31259/TCP                                 172m
    geo2                  NodePort       10.23.244.199               8106:31907/TCP                                 12d
    geo3                  NodePort       10.23.247.234               8106:30136/TCP                                 20h
    geo4                  NodePort       10.23.248.128               8106:32107/TCP                                 146m
  6.  登入 kong → APIS → 修改NAME geo-for test → Uris /geo1/v1 → https://geo1:8106
    測試是否正常運作
    <span class="hljs-string"><span class="hljs-string"><span class="hljs-string"><span class="hljs-string">https:</span></span></span></span><span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment"><span class="hljs-comment">//api.xxxxx.com/geo1/v1/get_geo_info/?ip=115.178.180.42&amp;apikey=ywhYbFyanJIr0q9xeJezgU884STJpoxu</span></span></span></span>
  7. 確認沒問題,加入 upstreams → geos DETAILS → Targets → 把 geo1 內網ip加進去