ClusterIP

ClusterIP结构示意图
ClusterIP结构示意图

创建 myapp-deploy.yaml 文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
[root@master manifests]# vim myapp-clusterip-deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp-clusterip-deploy
namespace: default
spec:
replicas: 3
selector:
  matchLabels:
    app: myapp
    release: stabel
    svc: clusterip
template:
  metadata:
    labels:
      app: myapp
      release: stabel
      env: test
      svc: clusterip
  spec:
    containers:
    - name: myapp-container
      image: wangyanglinux/myapp:v1.0
      imagePullPolicy: IfNotPresent
      ports:
      - name: http
        containerPort: 80
      readinessProbe:
        httpGet:
          port: 80
          path: /index1.html
        initialDelaySeconds: 1
        periodSeconds: 3

创建 Service 信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@master manifests]# vim myapp-service.yaml
apiVersion: v1
kind: Service
metadata:
name: myapp-clusterip
namespace: default
spec:
type: ClusterIP
selector:
  app: myapp
  release: stabel
  svc: clusterip
ports:
- name: http
  port: 80
  targetPort: 80

会话保持( IPVS持久化连接)

1
service.spec.sessionAffinity: ClientIP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[root@k8s-master01 ~]# kubectl explain svc.spec.sessionAffinityConfig.clientIP
KIND: Service
VERSION: v1

FIELD: clientIP <ClientIPConfig>


DESCRIPTION:
clientIP contains the configurations of Client IP based session affinity.
ClientIPConfig represents the configurations of Client IP based session
affinity.

FIELDS:
timeoutSeconds <integer>
timeoutSeconds specifies the seconds of ClientIP type session sticky time.
The value must be >0 && <=86400(for 1 day) if ServiceAffinity == "ClientIP".
Default value is 10800(for 3 hours).

服务内部流量策略

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[root@k8s-master01 ~]# kubectl explain svc.spec.internalTrafficPolicy
KIND: Service
VERSION: v1

FIELD: internalTrafficPolicy <string>
ENUM:
Cluster
Local

DESCRIPTION:
InternalTrafficPolicy describes how nodes distribute service traffic they
receive on the ClusterIP. If set to "Local", the proxy will assume that pods
only want to talk to endpoints of the service on the same node as the pod,
dropping the traffic if there are no local endpoints. The default value,
"Cluster", uses the standard behavior of routing to all endpoints evenly
(possibly modified by topology and other features).

Possible enum values:
- `"Cluster"` routes traffic to all endpoints.
- `"Local"` routes traffic only to endpoints on the same node as the client
pod (dropping the traffic if there are no local endpoints).