gongdear

gongdear的技术博客

欢迎大家参观我的博客
  menu
90 文章
89355 浏览
0 当前访客
ღゝ◡╹)ノ❤️

k8s创建redis集群

  1. 创建redis-master Pod和服务
    先定义RC来创建pod,然后定义与之关联的service。
    为redis-master服务新建一个名为redis-master-controller.yaml的RC定义文件,内容为:

apiVersion: v1
kind: ReplicationController
metadata:
name: redis-master
labels:
name: redis-master
spec:
replicas: 1
selector:
name: redis-master
template:
metadata:
labels:
name: redis-master
spec:
containers:
- name: master
image: kubeguide/redis-master
ports:
- containerPort: 6379
新建好文件之后执行如下命令:

kubectl create -f redis-master-controller.yaml
删除:将create换为delete即可。
查看刚刚新建的redis-master:

kubectl get rc
检查pod信息:

kubectl get pods
下面新建与上面建的pod相关联的service,service对应的文件redis-master-service.yaml,内容如下:

apiVersion: v1
kind: Service
metadata:
name: redis-master
labels:
name: redis-master
spec:
ports:

  • port: 6379
    targetPort: 6379
    selector:
    name: redis-master
    创建service:

kubectl create -f redis-master-service.yaml
查看新建的service:

kubectl get services
2. redis-slave Pod和服务
步骤和redis-master的一样。
新建文件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
env:
- name: GET_HOSTS_FROM
value: env
ports:
- containerPort: 6379
运行kubectl create命令:

kubectl create -f redis-slave-controller.yaml
查看RC:

kubectl get rc
查看pod:

kubectl get pods
配置文件redis-slave-service.yaml内容如下:

apiVersion: v1
kind: Service
metadata:
name: redis-slave
labels:
name: redis-slave
spec:
ports:

  • port: 6379
    selector:
    name: redis-slave

创建service:

kubectl create -f redis-slave-service.yaml
检查service:

kubectl get services;

宝剑锋从磨砺出,梅花香自苦寒来.