Docs/CloudNative/Kubernetes/Base/k8s-svc.md
2022-10-18 16:59:37 +08:00

45 lines
No EOL
1.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

```
apiVersion: v1
kind: Service
metadata:
name: svc-demo
namespace: default
spec:
selector: # 选择器与rs标签匹配
app: rs-demo
type: ClusterIP # 仅仅使用一个集群内部的IP地址 - 这是默认值。选择这个值意味着你只想这个服务在集群内部才可以被访问到
clusterIP: 172.10.1.9
ports:
port: 80
targetPort:80
```
```
apiVersion: v1
kind: Service
metadata:
name: svc-demo
namespace: default
spec:
selector: # 选择器与rs标签匹配
app: rs-demo
type: NodePort # 在集群内部IP的基础上在集群的每一个节点的端口上开放这个服务。你可以在任意<NodeIP>:NodePort地址上访问到这个服务。
# clusterIP: 172.10.1.9
ports:
port: 80
targetPort:80
```
```
apiVersion: v1
kind: Service
metadata:
name: svc-demo
namespace: default
spec:
selector: # 选择器与rs标签匹配
app: rs-demo
type: None # None无头svcheadless一般用于statefulset有状态的
# clusterIP: 172.10.1.9
ports:
port: 80
targetPort:80
```