K8s+docker: Deploy message Board Php+redis

Source: Internet
Author: User
Tags etcd k8s redis cluster

Preparation before you begin
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
disabling firewalls
servera and serverb and serverc disable firewalld
Configure NTP three servers to install Docker kubernetes

[Email protected]]# yum-y Install Docker

[[Email protected]]# systemctl Enable Docker && Systemctl start Docker

Configure Ali Agent

Vim/etc/docker/daemon.json

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

Systemctl daemon-reload && systemctl Restart Docker

[Email protected] ~]# 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

[Email protected]]# yum-y Install--enablerepo=virt7-testing kubernetes

Installing the Kubenetes database package

[Email protected]]# yum-y Install http://cbs.centos.org/kojifiles/packages/etcd/0.4.6/7.el7.centos/x86_64/ etcd-0.4.6-7.el7.centos.x86_64.rpm

This is configured on each node

[[Email protected]]# vi/etc/kubernetes/config

KUBE_MASTER="--master=http://serverc.lab.example.com:8080"KUBE_ETCD_SERVERS="--etcd_servers=http://serverc.lab.example.com:4001"
Configuration on ServerC (master) host

[Email protected] 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"
Restart Service Etcd kube-apiserver Kube-controller-manager Kube-scheduler

[Email protected] yum.repos.d]# ps-efw|grep kube

Modify the configuration on ServerA (node)

[Email protected] ~]# 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"
Restart Service Docker Kubelet Kube-proxy Error Resolution

No API token found for service account ' default ', retry after the token was automatically created and added to the service Account
The solution is to remove the Certified editor/etc/kubernetes/apiserver remove the Securitycontextdeny,serviceaccount in Kube_admission_control
Restart Kube-apiserver.service Service

[Email protected] ymal-pod]# systemctl restart Kube-apiserver.service

[[email protected] pod-yaml]# Kubectl get nodes

Create a database to create a 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
Create a service for Redis

[Email protected] 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
Troubleshooting:
[[email protected] ymal-pod]# kubectl describe pod redis-master-jr638需要在节点(node)上安装[[email protected] ymal-pod]# docker pull registry.access.redhat.com/rhel7/pod-infrastructure:latest[[email protected] ymal-pod]# yum install *rhsm*

[Email protected] 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

[Email protected] ymal-pod]# Kubectl create-f Redis-service.yaml

[[email protected] ymal-pod]# Kubectl get pods-o Wide

Create from Database

[Email protected] 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

[Email protected] ymal-pod]# VI Redis-slave-service.yaml

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

To realize the master-slave data synchronization of Redis cluster, redis-slave need to know the address of redis-master, so in Redis-slave image's boot command/run.sh, you can see the following content:
Redis-server--slaveof ${redis_master_service_host} 6379

Creating a front-end pod

[Email protected] 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
Create a front-end service

[Email protected] ymal-pod]# VI Frontend-service.yaml

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

[Email protected] pod-yaml]# Kubectl create-f Frontend-service.yaml

[[email protected] 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

[[email protected] ymal-pod]# Kubectl Get Service

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

firefox:http://serverb.lab.example.com:30001/

K8s+docker: Deploy message Board Php+redis

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.