1. 程式人生 > 其它 >|NO.Z.00159|——————————|CloudNative|——|KuberNetes&服務釋出.V10|-------------------------------------------------------|service.v02|外部地址發生更新|

|NO.Z.00159|——————————|CloudNative|——|KuberNetes&服務釋出.V10|-------------------------------------------------------|service.v02|外部地址發生更新|



[CloudNative:KuberNetes&服務釋出.V10]                                                               [Applications.KuberNetes] [在k8s中如何釋出服務|service|使用service代理k8s外部服務|使用service反代外部域名|service常用型別|]








一、外部應用地址發生變化,解決方案
### --- 更改endpoints配置引數
~~~     檢視百度地址
~~~     若是百度的地址或者目標地址變更了怎麼辦,我們只需要編輯endpoint就可以:
~~~     模擬編輯測試;代理一下淘寶的

[root@k8s-master01 ~]# ping taobao.com
PING taobao.com (140.205.220.96) 56(84) bytes of data.
### --- 編輯endpoints配置引數

[root@k8s-master01 ~]# vim nginx-ep-external.yaml 
subsets:
- addresses:
  - ip: 140.205.220.96
  ports:
  - name: http
    port: 80
    protocol: TCP 
二、重新觸發容器
### --- 重新觸發容器

[root@k8s-master01 ~]# kubectl replace -f nginx-ep-external.yaml 
endpoints/nginx-svc-external replaced
### --- 檢視重新觸發後endpoints容器對應的地址

[root@k8s-master01 ~]# kubectl get ep
NAME                 ENDPOINTS                                                          AGE
kubernetes           192.168.1.11:6443,192.168.1.12:6443,192.168.1.13:6443              11d
nginx-svc            172.17.125.13:443,172.18.195.18:443,172.17.125.13:80 + 1 more...   20h
nginx-svc-external   140.205.220.96:80 
三、檢視endpoints對應的service地址並驗證獲取的資料是否與測試資料一致
### --- 檢視建立的service地址

[root@k8s-master01 ~]# kubectl get svc
NAME                 TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
kubernetes           ClusterIP   10.96.0.1       <none>        443/TCP          11d
nginx-svc            ClusterIP   10.101.145.83   <none>        80/TCP,443/TCP   20h
nginx-svc-external   ClusterIP   10.97.162.95    <none>        80/TCP           12m
### --- 驗證獲取的資料是否與測試資料一致
~~~     可以看到返回值已經變為501,說明更新成功了

[root@k8s-master01 ~]# curl 10.97.162.95 -I
HTTP/1.1 501 Not Implemented                                   
Server: Tengine
Date: Wed, 21 Apr 2021 06:52:38 GMT
Content-Type: text/html
Content-Length: 583
Connection: close 








===============================END===============================


Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart                                                                                                                                                    ——W.S.Landor



來自為知筆記(Wiz)