k8s第一個實例建立redis集羣服務

一、建立redis-master-controller.yamljava

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

運行該實例:redis

kubectl  create -f redis-master-controller.yamlapi

二、建立redis-master-service.yamlfrontend

apiVersion: v1
kind: Service
metadata:
  name: redis-master
  labels:
    name: redis-master
spec:
  selector:
    name: redis-master
  ports:
  - port: 6379
    targetPort: 6379

運行 master-serviceide

  kubectl create -f redis-master-service.yamlui

三、建立 redis-slave-controller.yamlspa

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

運行:code

kubectl create -f redis-slave-controller.yamlblog

四、建立 redis-slave-controller.yamlget

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

五、建立  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來講,這個格式簡直是折磨人啊!!!!!

相關文章
相關標籤/搜索