天天看點

k8s實戰--edusoho平台建立

k8s實戰--edusoho平台建立

  1. 基本資訊說明

    使用kubeadm方式安裝kubernetes

    Kubernetes叢集添加/删除Node

    Kubernetes Dashboard1.8.3部署

    k8s原生的叢集監控方案(Heapster+InfluxDB+Grafana)

  2. 項目位址

    k8s-edusoho平台建立

  3. 鏡像下載下傳

    如上面的項目位址無法使用,請使用下面連結下載下傳相應鏡像

    docker pull wutengfei/lnmp-nginx (建構LNMP平台鏡像--nginx,nginx版本:nginx/1.13.0)
    docker pull wutengfei/lnmp-php (建構LNMP平台基礎鏡像php,php的版本:PHP 7.1.5)
    docker pull wutengfei/mysql (建構LNMP平台的基礎鏡像--mysql,mysql版本是:mysql:5.6)           
  4. 項目檔案結構和YAML檔案

    (1)項目檔案結構

    # pwd
    /data
    # tree -L 3
    .
    ├── mysql
    │   ├── conf
    │   │   └── my.cnf
    │   └── data
    ├── nginx
    │   ├── conf
    │   │   └── nginx.conf
    │   ├── edusoho
    │   │   ├── api
    │   │   ├── app
    │   │   ├── bootstrap
    │   │   ├── plugins
    │   │   ├── src
    │   │   ├── vendor
    │   │   ├── vendor_user
    │   │   └── web
    │   └── log
    │       └── error.log
    ├── php
    │   ├── log
    │   │   └── php-fpm.log
    │   ├── php-fpm.conf
    │   ├── php.ini
    │   └── www.conf           

(2)Pod的yaml檔案

apiVersion: v1
kind: Pod
metadata:
  name: lamp-edusoho
  labels:
    app: lamp-edusoho
restartPolicy: Always
spec:
  containers:
  - name: nginx
    abels:
      app: lamp-nginx
    image: dockerhub.datagrand.com/global/nginx:v1
    ports:
    - containerPort: 80
    volumeMounts:
      - name: datadir
        mountPath: "/var/log/nginx/error.log"
        subPath: ./nginx/log/error.log
      - name: datadir
        mountPath: "/etc/nginx/nginx.conf"
        subPath: ./nginx/conf/nginx.conf
      - name: datadir
        mountPath: "/usr/share/nginx/html"
        subPath: ./nginx/edusoho
  - name: php
    image: dockerhub.datagrand.com/global/php:v1
    ports:
    - containerPort: 9000
    volumeMounts:
      - mountPath: /usr/local/php/etc/php-fpm.conf
        name: datadir
        subPath: ./php/php-fpm.conf
      - mountPath: /usr/local/php/etc/php-fpm.d/www.conf
        name: datadir
        subPath: ./php/www.conf
      - mountPath: /usr/local/php/etc/php.ini
        name: datadir
        subPath: ./php/php.ini
      - mountPath: /usr/local/php/var/log/php-fpm.log
        name: datadir
        subPath: ./php/log/php-fpm.log
      - mountPath: /usr/share/nginx/html
        name: datadir
        subPath: ./nginx/edusoho
  - name: mysql
    image: dockerhub.datagrand.com/global/mysql:5.6
    ports:
    - containerPort: 3306
    env:
      - name: MYSQL_ROOT_PASSWORD
        value: "123456"
      - name: MYSQL_DATABASE
        value: "edusoho"
      - name: MYSQL_USER
        value: "edusoho"
      - name: MYSQL_PASSWORD
        value: "edusoho"
    args: ['--character-set-server=utf8']
    volumeMounts:
      - name: datadir
        mountPath: "/var/lib/mysql"
        subPath: ./mysql/data
      - name: datadir
        mountPath: "/etc/my.cnf"
        subPath: ./mysql/conf/my.cnf
  volumes:
  - name: datadir
    persistentVolumeClaim:
      claimName: nfs-pvc           

(3)PV的yaml檔案

apiVersion: v1
kind: PersistentVolume
metadata:
  name: nfs-pv
spec:
  capacity:
    storage: 4Gi
  accessModes:
    - ReadWriteMany
  nfs:
    server: 192.168.246.168  ##NFS伺服器的ip位址
    path: "/data"  ##NFS伺服器上的共享目錄
           

(4)PVC的yaml檔案

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nfs-pvc
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: ""
  resources:
    requests:
      storage: 3Gi           
apiVersion: v1
kind: Service
metadata:
  name: edusoho
  labels:
    app: edusoho
spec:
  type: NodePort 
  ports:
  - port: 80
    nodePort: 32756
  selector:
    app: lamp-edusoho           
檢視Pod
kubectl get po -o wide
檢視Service
kubectl get svc
進入容器内部某個應用,如這裡的nginx
kubectl exec -it lamp-edusoho -c nginx /bin/bash           
http://192.168.246.168:32756/install/start-install.php
說明:這裡的192.168.246.168是kubernetes的node節點IP,32756是Service中定義的nodePort。           

繼續閱讀