Et si on mettait PluXml dans un cluster k8s ?
Rédigé par dada / 11 novembre 2018 / Aucun commentaire
La création du conteneur
Introduction
Le Dockerfile
FROM php:7.0-apache
WORKDIR /var/www/html
RUN apt update
RUN apt install -y wget unzip
RUN wget https://git.dadall.info/dada/pluxml/raw/master/pluxml-latest.zip
RUN mv pluxml-latest.zip /usr/src/
#VOLUME
VOLUME /var/www/html
RUN a2enmod rewrite
RUN service apache2 restart
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
&& docker-php-ext-install -j$(nproc) iconv \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install -j$(nproc) gd
# Expose
EXPOSE 80
COPY entrypoint.sh /usr/local/bin/
ENTRYPOINT ["entrypoint.sh"]
CMD ["apache2-foreground"]
Comprendre le Dockerfile
Entrypoint ?
#!/bin/bash
if [ ! -e index.php ]; then
unzip /usr/src/pluxml-latest.zip -d /var/www/html/
mv /var/www/html/PluXml/* /var/www/html
rm -rf /var/www/html/PluXml
chown -R www-data: /var/www/html
fi
exec "$@"
Comprendre le entrypoint
La création de l'image
docker build -t pluxml-5.6 .
Successfully built d554d0753425
Successfully tagged pluxml-5.6:latest
Téléverser l'image dans un dépôt
Préparer Kubernetes
Le deployment & co
dada@k8smaster:~/pluxml$ cat pluxml.yaml
apiVersion: v1
kind: Service
metadata:
name: pluxml
labels:
app: pluxml
spec:
ports:
- port: 80
selector:
app: pluxml
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: plx-pv-claim
labels:
app: pluxml
spec:
storageClassName: rook-ceph-block
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 500Mi
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: pluxml
labels:
app: pluxml
spec:
strategy:
type: Recreate
template:
metadata:
labels:
app: pluxml
spec:
containers:
- image: dadall/pluxml-5.6:latest
imagePullPolicy: "Always"
name: pluxml
ports:
- containerPort: 80
name: pluxml
volumeMounts:
- name: pluxml-persistent-storage
mountPath: /var/www/html
volumes:
- name: pluxml-persistent-storage
persistentVolumeClaim:
claimName: plx-pv-claim
L'ingress
dada@k8smaster:~/pluxml$ cat pluxml-ingress.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: nginx
name: pluxml-ingress
spec:
backend:
serviceName: pluxml
servicePort: 80
dada@k8smaster:~/pluxml$ kubectl create -f pluxml.yaml
dada@k8smaster:~/pluxml$ kubectl create -f pluxml-ingress.yaml
dada@k8smaster:~/pluxml$ kubectl get pods --all-namespaces -o wide | grep plux
default pluxml-686f7d486-7p5sq 1/1 Running 0 82m 10.244.2.164 k8snode2 <none>
dada@k8smaster:~/pluxml$ kubectl describe svc pluxml
Name: pluxml
Namespace: default
Labels: app=pluxml
Annotations: <none>
Selector: app=pluxml
Type: ClusterIP
IP: 10.100.177.201
Port: <unset> 80/TCP
TargetPort: 80/TCP
Endpoints: 10.244.1.31:80
Session Affinity: None
Events: <none>
dada@k8smaster:~/pluxml$ kubectl describe ingress pluxml
Name: pluxml-ingress
Namespace: default
Address:
Default backend: pluxml:80 (10.244.1.31:80,10.244.2.164:80)
Rules:
Host Path Backends
---- ---- --------
* * pluxml:80 (10.244.1.31:80,10.244.2.164:80)
Annotations:
kubernetes.io/ingress.class: nginx
Events: <none>