k8s第一个实例创建redis集群服务
1、创建redis-master-controller.yaml
apiVersion: v1 kind: ReplicationController metadata: name: redis-master labels: name: redis-master spec: replicas: 2 selector: name: redis-master template: metadata: labels: name: redis-master spec: containers: - name: master image: redis ports: - containerPort: 6379
运行该实例:
kubectl create -f redis-master-controller.yaml
2、创建redis-master-service.yaml
apiVersion: v1 kind: Service metadata: name: redis-master labels: name: redis-master spec: selector: name: redis-master ports: - port: 6379 targetPort: 6379
运行 master-service
kubectl create -f redis-master-service.yaml
3、创建 redis-slave-controller.yaml
apiVersion: v1 kind: ReplicationController metadata: name: redis-slave labels: name: redis-slave spec: replicas: 2 selector: name: redis-slave template: metadata: labels: name: redis-slave spec: containers: - name: slave image: kubeguide/guestbook-redis-slave ports: - containerPort: 6379 env: - name: GET_HOSTS_FROM value: env
运行:
kubectl create -f redis-slave-controller.yaml
4、创建 redis-slave-controller.yaml
apiVersion: v1 kind: ReplicationController metadata: name: redis-slave labels: name: redis-slave spec: replicas: 2 selector: name: redis-slave template: metadata: labels: name: redis-slave spec: containers: - name: slave image: kubeguide/guestbook-redis-slave ports: - containerPort: 6379 env: - name: GET_HOSTS_FROM value: env
运行 kubectl create -f redis-slave-controller.yaml
5、创建 redis-slave-service.yaml
apiVersion: v1 kind: Service metadata: name: redis-slave labels: name: redis-slave spec: selector: name: redis-slave ports: - port: 6379
运行
kubectl create -f redis-slave-service.yaml
查看运行pods
[root@k8s_ceshi mall-abbott]# kubectl get pods
NAME READY STATUS RESTARTS AGE
frontend-14jz9 0/1 ContainerCreating 0 15m
frontend-h6v6b 0/1 ContainerCreating 0 15m
frontend-ld67s 0/1 ContainerCreating 0 15m
redis-master-8ck0d 0/1 ContainerCreating 0 20m
redis-master-vg19j 0/1 ContainerCreating 0 20m
redis-slave-56l6b 0/1 ContainerCreating 0 17m
redis-slave-5h0rv 0/1 ContainerCreating 0 17m
在创建的过程中一定要按照格式来写,尤其是空格,对于自由写代码的coder来说,这个格式简直是折磨人啊!!!!!