1 说明

由于需要部署多个项目,希望能用同一个镜像和不同vhost.conf ,vhost.conf 用ConfigMap 进行配置, 然后再用volumeMounts 挂载的方式 将vhost.conf 生成在apache的conf 目录下

2. vhost.conf 的ConfigMap 配置

vi phpipam.ConfigMap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  namespace: yzdxxx
  name: phpipam-cm
data:
  phpipam_conf: |-
    <VirtualHost *:80>  
       AddType application/x-httpd-php .php
       DirectoryIndex index.php index.htm index.html
       ServerName phpipam.dev.yzdxxx.net
       ErrorLog logs/phpipam-error.log
       CustomLog logs/phpipam-access_log combined
       DocumentRoot "/var/www/phpIPAM"
       <Directory "/var/www/phpIPAM"> 
          Require all granted
          Options FollowSymLinks
          AllowOverride None
          Order deny,allow
          Allow from all
       </Directory>
    </VirtualHost>

然后执行 phpipam.ConfigMap.yaml

[root@VM-102-12-centos /data/swinglau007]# kubectl apply -f phpipam.ConfigMap.yaml 
configmap/phpipam-cm created

3. Deployment.yaml

vi phpipam.Deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  namespace: yzdxxx
  name: phpipam-dpy
  labels:
    app: phpipam
spec:
  replicas: 1
  selector:
    matchLabels:
      app: phpipam
  template:
    metadata:
      labels:
        app: phpipam
    spec:
      containers:
      - name: phpipam
        image: mirrors.dockerSite.com/go.project/goipam:202106031520 
        ports:
        - containerPort: 80
        volumeMounts:
        - name: phpipam-volume
          mountPath: /etc/apache2/conf.d/ 
      volumes:
        - name: phpipam-volume
          configMap:
            name: phpipam-cm
            defaultMode: 420
            items:
            - key: phpipam_conf
              mode: 420
              path: phpipam.conf 

然后执行 phpipam.Deployment.yaml

[root@VM-102-12-centos /data/swinglau007]# kubectl apply -f phpipam.Deployment.yaml 
Deployment/phpipam-dpy created

4. k8s 自动更新镜像

当前k8s机器 更新

kubectl set image deployment/phpipam-dpy phpipam=mirrors.dockerSite.com/go.project/goipam:202106031832 -n yzdxxx

远程非 k8s机器更新

sshpass -p 'mypassword' ssh -q -o StrictHostKeyChecking=no -p 22 root@myhostIP  "kubectl set image deployment/phpipam-dpy phpipam=mirrors.dockerSite.com/go.project/goipam:202106031832 -n yzdxxx"
Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐