k8s-通过yaml 启动使用redis主从-实例

By | 2017年5月22日

1、需要四个yaml格式的文件,master-po、master-server、 slave-po、slave-server

root@localhost:/opt/redis/test# vim redis-master-service.yaml 
apiVersion: v1
kind: Service
metadata:
  name: redis-master-uytrd
  labels:
    name: redis-master-uytrd
spec:
  type: NodePort
  ports:
  - port: 6379
    nodePort:
  selector:
    name: redis-master-uytrd
root@localhost:/opt/redis/test# vim redis-master.yaml 
apiVersion: v1
kind: Pod
metadata:
  name: redis-master-podrkydc
  labels:
    name : redis-master-uytrd
spec:
  containers:
    - name: master
      image: kubeguide/redis-master
      ports:
        - containerPort: 6379
      resources:
          limits:
            cpu: 0.5
            memory: 100Mi
  nodeName: node-01                (node-节点名称)
root@localhost:/opt/redis/test# vim redis-slave-service.yaml
apiVersion: v1
kind: Service
metadata:
  name: redis-slave-uytrdi
  labels:
    name: redis-slave-uytrdi
spec:
  type: NodePort
  ports:
  - port: 6379
    nodePort:
  selector:
    name: redis-master-uytrd            Master名称
root@localhost:/opt/redis/test# vim redis-master.yaml 
apiVersion: v1
kind: Pod
metadata:
  name: redis-master-podrkydc
  labels:
    name : redis-master-uytrd
spec:
  containers:
    - name: master
      image: kubeguide/redis-master
      ports:
        - containerPort: 6379
      resources:
          limits:
            cpu: 0.5
            memory: 100Mi
  nodeName: node-01     Node机器名

四个文件以此创建,先创建Master

root@localhost:/opt/redis/test# kubectl create -f redis-master-service.yaml

删除为:

kubeclt delete -f

查看svc与po

root@localhost:/opt/redis/test# kubectl get svc -o wide
NAME                 CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE       SELECTOR
kubernetes           10.96.0.1       <none>        443/TCP          9h        <none>
redis-master-uytrd   10.108.147.65   <nodes>       6379:30700/TCP   5h        name=redis-master-uytrd
redis-slave-uytrdi   10.104.57.186   <nodes>       6379:30103/TCP   5h        name=redis-master-uytrd

 

root@localhost:/opt/redis/test# kubectl get po -o wide

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注