service
--pod-network-cidr=10.244.0.0/16 (pod网段)
--service-cidr=10.96.0.0/12 (service网段)
[root@master maintest]# cat pod.yaml
apiVersion: apps/v1
kind: Deployment
Metadata:
name: my-Nginx
spec:
selector:
matchLabels:
run: my-Nginx
replicas: 2
template:
Metadata:
labels:
run: my-Nginx
spec:
containers:
- name: my-Nginx
image: Nginx
ports:
- containerPort: 80
service 默认type类型为ClusterIP
[root@master maintest]# cat service.yaml
apiVersion: v1
kind: Service
Metadata:
name: my-Nginx
labels:
run: my-Nginx
spec:
ports:
- port: 80
protocol: TCP
selector:
run: my-Nginx
service 代理到对应的后端pod
映射到宿主机端口
.service.spec.type
NodePort
apiVersion: v1
kind: Service
Metadata:
name: my-Nginx
labels:
run: my-Nginx
spec:
ports:
- port: 80
protocol: TCP
type: NodePort
selector:
run: my-Nginx
[root@master maintest]# kubectl get svc -o wide
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 69d <none>
my-Nginx NodePort 10.106.132.151 <none> 80:30994/TCP 21h run=my-Nginx
访问node节点的ip:30994---->service ip:80---->pod ip:80
创建没有selector的service
[root@master maintest]# cat noselector.yaml
apiVersion: v1
kind: Service
Metadata:
name: my-service
spec:
ports:
- port: 80
protocol: TCP
targetPort: 3306
endpoint.yaml
[root@master maintest]# cat endpoint.yaml
apiVersion: v1
kind: Endpoints
Metadata:
name: my-service
subsets:
- addresses:
- ip: 1.2.3.4
ports:
- port: 3306
[root@master maintest]# kubectl describe svc my-service
Name: my-service
Namespace: default
Labels: <none>
Annotations: <none>
Selector: <none>
Type: ClusterIP
IP Families: <none>
IP: 10.104.205.156
IPs: <none>
Port: <unset> 80/TCP
TargetPort: 3306/TCP
Endpoints: 1.2.3.4:3306
Session Affinity: None
Events: <none>
创建type是ExternalName的service
[root@master maintest]# cat external.yaml
apiVersion: v1
kind: Service
Metadata:
name: my-service
namespace: prod
spec:
type: ExternalName
externalName: my.database.example.com
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。