CenterOS 7 kubernetes安装及集成mysql、redis

1.安装并启动kubernetes

(1)关闭防火墙

systemctl disable firewalld

systemctl stop firewalld

(2)安装etcd及Kubernetes

yum install -y etcd kubernetes

(3)修改/etc/kubernetes/apiserver

去除 KUBE_ADMISSION_CONTROL中的SecurityContextDeny,ServiceAccount,并重启kube-apiserver.service服务:
systemctl restart kube-apiserver.service

(4)按顺序启动所有服务

systemctl start ectd

systemctl start docker

systemctl start kube-apiserver

systemctl start kube-controller-manager

systemctl start kube-scheduler

systemctl start kubelet

systemctl start kube-proxy

2.启动mysql

(1)任意目录下创建mysql-rc.yaml

apiVersion: v1

kind: ReplicationController

metadata:

name: mysql

spec:

replicas: 1

selector:

app: mysql

template:

metadata:

labels:

app: mysql

spec:

containers:

- name: mysql

image: mysql

ports:

- containerPort: 3306

env:

- name: MYSQL_ROOT_PASSWORD

value: "123456"

(2)发布至kubernetes集群中

kubectl create -f mysql-rc.yaml

(3)创建mysql服务文件mysql-svc.yaml

apiVersion: v1

kind: Service

metadata:

name: mysql

spec:

type: NodePort

ports:

- port: 3306

nodePort: 30306

selector:

app: mysql

安装好后可通过服务器地址:mysql-svc.yaml中nodePort访问mysql数据库

3.启动redis

(1)创建redis-rc.yaml

apiVersion: v1

kind: ReplicationController

metadata:

name: redis

spec:

replicas: 1

selector:

app: redis

template:

metadata:

labels:

app: redis

spec:

containers:

- name: redis

image: redis

ports:

- containerPort: 6379

(2)发布至kubernetes集群中

kubectl create -f redis-rc.yaml

(3)创建redis服务文件redis-svc.yaml

apiVersion: v1

kind: Service

metadata:

name: redis

spec:

type: NodePort

selector:

app: redis

ports:

- name: "1"

port: 6379

protocol: TCP

targetPort: 6379

nodePort: 31009

安装好后可通过服务器地址:mysql-svc.yaml中nodePort访问mysql数据库

你可能感兴趣的:(CenterOS 7 kubernetes安装及集成mysql、redis)