Pages - Menu

2021年3月22日 星期一

[k8s] kubernets yaml筆記篇

前言

最近寫yaml,有時常會忘記這個的功能是什麼,就記一下吧。

看來我真的快變成yaml工程師了。


正文

  1. Service 的Port功能


Port exposes the Kubernetes service on the specified port within the cluster. Other pods within the cluster can communicate with this server on the specified port.

    TargetPort is the port on which the service will send requests to, that your pod will be listening on. Your application in the container will need to be listening on this port also.

    NodePort exposes a service externally to the cluster by means of the target nodes IP address and the NodePort. NodePort is the default setting if the port field is not specified.

    1. 探針檢查

    livenessProbe:
      initialDelaySeconds: 10
      periodSeconds: 10
      successThreshold: 1
      failureThreshold: 3
      tcpSocket:
        port: 80
    readinessProbe:
      initialDelaySeconds: 30
      periodSeconds: 10
      successThreshold: 1
      failureThreshold: 3
      tcpSocket:
        port: 80
    

    1. pull image 認證


    如果要佈署的image是屬於 私密的,
    需要加上
      imagePullSecrets:
        - name: regcred
      

      要先注入Secred

      kubectl create secret generic regcred --from-file=./username.txt
      

      1. Service 服務類型

      • ClusterIP
        • 一個集群內的服務,集群內的其它應用都可以訪問該服務。集群外部無法訪問它。 這也是默認的 ServiceType。
        • 可以使用proxy 的本機 port轉移,來訪問服務。像 (Fig.1)

        • (Fig.1)
      • NodePort
        • 在所有節點(虛擬機)上開放一個特定端口,任何發送到該端口的流量都被轉發到對應服務。
        • 在 1 的service port,就是指這個部分。
        • 需使用K8s的叢集主機加上port,去訪問服務。 (Fig.2)


          (Fig.2)
      • LoadBalancer
        • LoadBalancer 服務是暴露服務到 internet 的標準方式。在 GKE 上,這種方式會啟動一個 Network Load Balancer,它將給你一個單獨的 IP 地址,轉發所有流量到你的服務。
        • 一個外部ip,直接訪問即可,有時需注意防火牆有沒有擋住。

      ref.
      Kubernetes的三種外部訪問方式:NodePort、LoadBalancer 和 Ingress
      Kubernetes 服務

      1. kube dns

      Pod DNS record



      (fig.3)
        172-17-0-6.default.pod.cluster.local
      
      • 172-17-0-6: Pod IP
      • default: Namespace Name

      Service DNS record



      (fig.4)

        nginx.default.svc.cluster.local
      
      • nginx: Service Name
      • default: Namespace Name

      Service Discovery


      (fig.5)

        web-0.nginx.default.svc.cluster.local
      
      • web-0: Pod Name
      • nginx: Service Name
      • default: Namespace Name

      5. Auto Scaling(自動擴展)

      在Auto Scaling 裡面,有一個設定是根據cpu的使用量大小去增加Pod,
      假設
      targetCPUUtilizationPercentage:10
      在deploy 裡的request CPU 設定 200m
      表示,當cpu的使用率在 20m(200m * 10% = 20m )時,會自動擴展

      如果要使用其他的指標,api 需改用 autoscaling/v2beta2
      這邊還沒測試過,有需要的可至相關網頁查詢


      ref.
      Kubernetes 那些事 — Auto Scaling
      Kubernetes–k8s–進階–全面瞭解HPA–部署HPA實現高可用和成本控制
      Kubernetes 1.8: Now with 100% Daily Value of Custom Metrics

      沒有留言:

      張貼留言