博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
k8s+docker:部署留言板php+redis
阅读量:6033 次
发布时间:2019-06-20

本文共 6258 字,大约阅读时间需要 20 分钟。

开始前的准备

dhcpdns.lab.example.com 192.168.0.5  dhcp+dns+ntpserverc.lab.example.com 192.168.0.30 as a master serverservera.lab.example.com 192.168.0.10 serverb.lab.example.com 192.168.0.20

禁用防火墙

servera and serverb and serverc disable firewalld

配置NTP

三台服务器都安装docker kubernetes

[root@server]# yum -y install docker

[root@server]# systemctl enable docker && systemctl start docker

配置阿里代理

vim /etc/docker/daemon.json

{        "registry-mirrors": ["https://0i5z79j3.mirror.aliyuncs.com"]    }

systemctl daemon-reload && systemctl restart docker

[root@serverc ~]# vi /etc/yum.repos.d/virt7-testing.repo

[virt7-testing]name=virt7-testingbaseurl=http://cbs.centos.org/repos/virt7-docker-el-testing/x86_64/os/gpgcheck=0

[root@server]# yum -y install --enablerepo=virt7-testing kubernetes

安装kubenetes的数据库包

[root@server]# yum -y install

这个在每个节点上都配置

[root@server]# vi /etc/kubernetes/config

KUBE_MASTER="--master=http://serverc.lab.example.com:8080"KUBE_ETCD_SERVERS="--etcd_servers=http://serverc.lab.example.com:4001"

serverc(master)主机上配置

[root@serverc yum.repos.d]# vi /etc/kubernetes/apiserver

KUBE_API_ADDRESS="--insecure-bind-address=0.0.0.0"KUBE_API_PORT="--port=8080"# KUBE_ETCD_SERVERS="--etcd-servers=http://127.0.0.1:2379"

重启服务 etcd kube-apiserver kube-controller-manager kube-scheduler

[root@serverc yum.repos.d]# ps -efw|grep kube

修改servera(node)上的配置

[root@servera ~]# vi /etc/kubernetes/kubelet

KUBELET_ADDRESS="--address=0.0.0.0"KUBELET_PORT="--port=10250"KUBELET_HOSTNAME="--hostname-override=servera.lab.example.com"KUBELET_API_SERVER="--api_servers=http://serverc.lab.example.com:8080"

重启服务 docker kubelet kube-proxy

报错解决方案

No API token found for service account "default", retry after the token is automatically created and added to the service account

解决办法是去除认证编辑/etc/kubernetes/apiserver 去除 KUBE_ADMISSION_CONTROL中的SecurityContextDeny,ServiceAccount
并重启kube-apiserver.service服务

[root@serverc ymal-pod]# systemctl restart kube-apiserver.service

[root@serverc pod-yaml]# kubectl get nodes

创建数据库

创建redis的pod

apiVersion: v1kind: ReplicationControllermetadata:    name: redis-master    labels:        name: redis-masterspec:    replicas: 1    selector:        name: redis-master    template:        metadata:            labels:                name: redis-master        spec:            containers:            - name: master                image: kubeguide/redis-master                ports:                - containerPort: 6379

创建redis的service

[root@serverc pod-yaml]# vi redis-master.yaml

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

排错:

[root@serverc ymal-pod]# kubectl describe pod redis-master-jr638需要在节点(node)上安装[root@serverc ymal-pod]# docker pull registry.access.redhat.com/rhel7/pod-infrastructure:latest[root@serverc ymal-pod]# yum install *rhsm*

[root@serverc ymal-pod]# vi redis-service.yaml

apiVersion: v1kind: Servicemetadata:    name: redis-master    labels:        name: redis-masterspec:    ports:    - port: 6379        targetPort: 6379    selector:        name: redis-master

[root@serverc ymal-pod]# kubectl create -f redis-service.yaml

[root@serverc ymal-pod]# kubectl get pods -o wide

创建从数据库

[root@serverc ymal-pod]# vi redis-slave.yaml

apiVersion: v1kind: ReplicationControllermetadata:    name: redis-slave    labels:        name: redis-slavespec:    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

[root@serverc ymal-pod]# vi redis-slave-service.yaml

apiVersion: v1kind: Servicemetadata:    name: redis-slave    labels:        name: redis-slavespec:    ports:    - port: 6379    selector:        name: redis-slave

实现redis集群的主从数据同步, redis-slave需要知道redis-master的地址,所以在redis-slave镜像的启动命令/run.sh 中,可以看到如下内容:

redis-server --slaveof ${REDIS_MASTER_SERVICE_HOST} 6379

创建前端pod

[root@serverc ymal-pod]# vi frontend-pod.yaml

apiVersion: v1kind: ReplicationControllermetadata:    name: frontend    labels:        name: frontendspec:    replicas: 3    selector:        name: frontend    template:        metadata:            labels:                name: frontend        spec:            containers:            - name: frontend                image: kubeguide/guestbook-php-frontend                env:                - name: GET_HOSTS_FROM                    value: env                ports:                - containerPort: 80

创建前端service

[root@serverc ymal-pod]# vi frontend-service.yaml

Version: v1kind: Servicemetadata:    name: frontend    labels:        name: frontendspec:    type: NodePort    ports:    - port: 80        nodePort: 30001    selector:        name: frontend

[root@serverc pod-yaml]# kubectl create -f frontend-service.yaml

[root@serverc ymal-pod]# kubectl get pod -o wide

NAME                 READY     STATUS    RESTARTS   AGE       IP           NODEfrontend-22b67       1/1       Running   0          4m        172.17.0.3   servera.lab.example.comfrontend-lksvk       1/1       Running   0          4m        172.17.0.4   serverb.lab.example.comfrontend-v81wh       1/1       Running   0          4m        172.17.0.4   servera.lab.example.comredis-master-xbkwj   1/1       Running   0          51m       172.17.0.2   serverb.lab.example.comredis-slave-cqj43    1/1       Running   0          32m       172.17.0.2   servera.lab.example.comredis-slave-q1q4j    1/1       Running   0          32m       172.17.0.3   serverb.lab.example.com

[root@serverc ymal-pod]# kubectl get service

NAME           CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGEfrontend       10.254.127.111   
80:30001/TCP 21skubernetes 10.254.0.1
443/TCP 1hredis-master 10.254.20.7
6379/TCP 42mredis-slave 10.254.156.197
6379/TCP 29m

firefox:

转载于:https://blog.51cto.com/11732619/2065102

你可能感兴趣的文章
TOJ4537: n阶行列式
查看>>
算法刷题笔记-stack-四则运算
查看>>
3.16
查看>>
Linux下arp用法
查看>>
表单文件上传与文件下载
查看>>
jquery 中prop()的使用方法
查看>>
下午考
查看>>
WKWebView
查看>>
创建字符设备的三种方法
查看>>
走在网页游戏开发的路上(六)
查看>>
nginx 配置的server_name参数(转)
查看>>
Uva592 Island of Logic
查看>>
C++基础代码--20余种数据结构和算法的实现
查看>>
footer固定在页面底部的实现方法总结
查看>>
nginx上传文件大小
查看>>
数字通信原理笔记(一)---概述
查看>>
HDU 2243 考研路茫茫——单词情结(自动机)
查看>>
Dubbo OPS工具——dubbo-admin & dubbo-monitor
查看>>
如何将OpenCV中的Mat类绑定为OpenGL中的纹理
查看>>
CutyCapt
查看>>