集群内访问表示工作负载暴露给同一集群内其他工作负载访问的方式,可以通过“集群内部域名”访问。
集群内部域名格式为“<自定义的服务名称>.<工作负载所在命名空间>.svc.cluster.local:<端口号>”,例如“nginx.default.svc.cluster.local:80”。
访问通道、容器端口与访问端口映射如图1所示。
您可以在创建工作负载时通过CCE控制台设置Service访问方式,如下:
您可以在工作负载创建完成后对Service进行配置,此配置对工作负载状态无影响,且实时生效。具体操作如下:
方式一:通过IP地址验证。
curl 10.247.74.100:8080
其中10.247.74.100:8080为步骤3中获取的访问地址。
回显如下表示工作负载可正常访问。
<html> <head> <title>Welcome to nginx!</title> <style> body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html>
方式二:进入容器,在容器内通过域名验证。
curl nginx.default.svc.cluster.local:8080
其中nginx.default.svc.cluster.local为步骤3中获取的域名访问地址。
回显如下表示工作负载可正常访问。
<html> <head> <title>Welcome to nginx!</title> <style> body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html>
您可以在添加完Service后,更新此Service的端口配置,操作步骤如下:
您可以通过kubectl命令行设置Service访问方式。本节以nginx为例,说明kubectl命令实现集群内访问的方法。
前提条件
请参见通过kubectl或web-terminal插件操作CCE集群配置kubectl命令,使弹性云服务器连接集群。
操作步骤
其中,nginx-deployment.yaml和nginx-clusterip-svc.yaml为自定义名称,您可以随意命名。
apiVersion: apps/v1 kind: Deployment metadata: name: nginx spec: replicas: 1 selector: matchLabels: app: nginx strategy: type: RollingUpdate template: metadata: labels: app: nginx spec: containers: - image: nginx imagePullPolicy: Always name: nginx imagePullSecrets: - name: default-secret
apiVersion: v1 kind: Service metadata: labels: app: nginx name: nginx-clusterip spec: ports: - name: service0 port: 8080 protocol: TCP targetPort: 80 selector: app: nginx type: ClusterIP
参数 |
是否必填 |
参数类型 |
描述 |
---|---|---|---|
port |
是 |
Integer |
将由此服务公开的端口,对应界面上的访问端口。 |
targetPort |
是 |
Integer |
对应界面上的容器端口。 |
type |
否 |
String |
对应界面上的访问类型,必须是:
默认值:ClusterIP,表示“集群虚拟IP”。 |
kubectl create -f nginx-deployment.yaml
回显如下,表示工作负载已开始创建。
deployment "nginx" created
kubectl get po
回显如下,工作负载状态为Running,表示工作负载已处于运行中状态。
NAME READY STATUS RESTARTS AGE etcd-0 0/1 ImagePullBackOff 0 27m icagent-m9dkt 0/0 Running 0 3d nginx-2601814895-znhbr 1/1 Running 0 15s
kubectl create -f nginx-ClusterIp-svc.yaml
回显如下,表示服务已开始创建。
service "nginx-clusterip" created
kubectl get svc
回显如下,表示服务已创建成功,CLUSTER-IP已生成。
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE etcd-svc ClusterIP None <none> 3120/TCP 30m kubernetes ClusterIP 10.247.0.1 <none> 443/TCP 3d nginx-clusterip ClusterIP 10.247.200.134 <none> 80/TCP 20s
方式一:通过IP地址验证。
curl 10.247.200.134:80
回显如下表示工作负载可正常访问。
<html> <head> <title>Welcome to nginx!</title> <style> body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html>
方式二:通过域名验证。
curl nginx-clusterip.default.svc.cluster.local:8080
回显如下表示工作负载可正常访问。
<html> <head> <title>Welcome to nginx!</title> <style> body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html>
使用obsutil下载文件夹前期速度正常,下载到90%后速度变慢 使用obsutil下载文件...
怎样注册网址 域名 ?注册网址域名,首先需要选择一个域名服务商,注册并登录会...
云虚拟主机 采用 云计算 ,比传统 虚拟主机 性能更稳定、安全,因此也得到了很多...
12月19日,在腾讯2020 Techo Park开发者大会上,腾讯云容器产品总经理邹辉通过代...
弹性负载均衡有不同的负载均衡,分别是 共享型 负载均衡和经典型负载均衡,便于...
费用组成 负载均衡(CLB)的费用由三部分组成:CLB 实例费、公网网络费、跨地域...
随着YouTube、Udemy、Coursera、可汗学院(Khan Academy)和各种编程训练营的兴起...
1. 创建腾讯云账号 如果您还没有腾讯云账号,请登录到 腾讯云官方网站,单击右上...
在您开通弹性容器实例时,需要授予名称AliyunECIContainerGroupRole的系统默认角...
近年来,金融业高度关注5G技术应用,一方面金融机构希望抓住5G应用发展窗口期,...