Kubernetes的ExternalName详解

ExternalName类型的Service在Kubernetes中用于将外部服务(不是Kubernetes集群内的服务)映射到Kubernetes集群内的Service。

样例

其创建方法如下:

kind: Service
apiVersion: v1
metadata:
  name: my-external-service
  namespace: cv-console-dev
  labels:
    app: my-external-service
  annotations:
    kubesphere.io/creator: sunjq
    kubesphere.io/serviceType: externalservice
spec:
  type: ExternalName
  sessionAffinity: None
  externalName: www.httpclient.cn

在上述配置中,我们创建了一个名为my-external-service的Service,其类型为ExternalName,并将www.httpclient.cn映射到该Service。这就相当于在Kubernetes集群内部创建了一个别名,可以通过访问my-external-service来访问www.httpclient.cn。

需要注意的是,使用ExternalName类型的Service需要确保目标外部服务已经存在,并且可以通过域名进行访问。

测试过程

root@5c856df78-5ml9f:/# curl -k  test-ex.cv-console-dev -vvv
*   Trying 47.244.242.115:80...
* Connected to test-ex.cv-console-dev (47.244.242.115) port 80 (#0)     ---------------------外部的域名对应的ip
> GET / HTTP/1.1
> Host: test-ex.cv-console-dev
> User-Agent: curl/7.74.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Server: nginx/1.15.12
< Date: Thu, 31 Aug 2023 08:49:05 GMT
< Content-Type: text/html
< Content-Length: 612
< Last-Modified: Fri, 21 Jun 2019 06:42:16 GMT
< Connection: keep-alive
< ETag: "5d0c7c48-264"
< Accept-Ranges: bytes
<



Welcome to nginx!



Welcome to nginx!

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.

* Connection #0 to host test-ex.cv-console-dev left intact

你可能感兴趣的:(kubernetes,kubernetes,云原生,容器)