02.关于Headless Service的一些实验(废弃)

在我的环境中,base-environment下有相应Service和HeadlessService可以用来实验,所以我计划在该命名空间下进行实验。

1
2
3
4
5
6
7
8

kubectl get svc -n base-environment

# NAME             TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
# redis-headless   ClusterIP   None             <none>        6379/TCP   21h
# redis-master     ClusterIP   10.101.228.148   <none>        6379/TCP   21h
# redis-replicas   ClusterIP   10.110.178.186   <none>        6379/TCP   21h

  1. 准备一个Busybox:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21

apiVersion: v1
kind: Pod
metadata:
  name: mybusybox
  namespace: base-environment
  labels:
    name: mybusybox
spec:
  containers:
  - name: mybusybox
    image: busybox
    command:
      - sh
      - -c
      - "while true;do echo hello docker;sleep 10;done"
    resources:
      limits:
        memory: "128Mi"
        cpu: "500m"

  1. 查看各个service

nslookup redis-headless.base-environment.svc.cluster.local
nslookup redis-master
nslookup redis-replicas