John Davidson

kubernetes - Can't replace pod with php in telepresence

0 comments
Message:


The bottom line is that I need to replace the pod with php code in the kubernetes cluster with a docker container using telepresence, this pod contains 2 containers: php and nginx.
I do everything according to the instructions (https://www.telepresence.io/tutorials/php) but it seems kubernetes does not see my container.


I run the cluster locally on minikube version 1.16.0, kubernetes version 1.20.0. I am using the NodePort service to access the application. After swap the pod, I get a 404 error.


This is how I find the external address: addr = kubectl get nodes -o jsonpath='{ $.items[*].status.addresses[?(@.type=="InternalIP")].address }'


Target browser address: addr + :30000


Spoof command: telepresence --swap-deployment telepresence-php --docker-run --rm -v$(pwd)/web:/var/www/html telepresence-dev


Kubernetes php + nginx pod settings:


apiVersion: apps/v1
kind: Deployment
metadata:
name: telepresence-php
spec:
replicas: 1
selector:
matchLabels:
svc: telepresence-php
template:
metadata:
labels:
svc: telepresence-php
spec:
containers:
- name: telepresence-php
image: mavellol/telepresence-php
ports:
- containerPort: 9000
volumeMounts:
- name: shared-files
mountPath: /var/www/html
lifecycle:
postStart:
exec:
command: ["/bin/sh", "-c", "cp -r /app/. /var/www/html"]
- name: telepresence-nginx
image: mavellol/telepresence-nginx
ports:
- containerPort: 80
volumeMounts:
- name: shared-files
mountPath: /var/www/html
volumes:
- name: shared-files
emptyDir: {}
---
apiVersion: v1
kind: Service
metadata:
name: telepresence-np
spec:
type: NodePort
ports:
- port: 80
targetPort: 80
nodePort: 30000
selector:
svc: telepresence-php

Kubernetes mysql pod settings


apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: telepresence-db
spec:
replicas: 1
selector:
matchLabels:
svc: telepresence-db
template:
metadata:
labels:
svc: telepresence-db
spec:
containers:
- name: telepresence-db
image: mavellol/telepresence-db
ports:
- name: db-port
containerPort: 3306
volumes:
- name: telepresence-mysql-data
persistentVolumeClaim:
claimName: telepresence-mysql-pvc
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: telepresence-mysql
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
- ReadOnlyMany
persistentVolumeReclaimPolicy: Retain
hostPath:
path: /tmp/telepresence-mysql
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: telepresence-mysql-pvc
spec:
resources:
requests:
storage: 1Gi
accessModes:
- ReadWriteOnce
storageClassName: ""
---
apiVersion: v1
kind: Service
metadata:
name: telepresence-db
spec:
ports:
- name: db-port
port: 3306
targetPort: db-port
selector:
svc: telepresence-db

docker container with which I substitute the php + nginx pod.


FROM nanoninja/php-fpm:latest

RUN apt-get update && apt-get install nginx -y
ADD ./etc/nginx/default.conf /etc/nginx/conf.d/default.conf
RUN rm /etc/nginx/sites-enabled/default

CMD nginx && php-fpm

Nginx default.conf settings:


server {
listen 80 default_server;
listen [::]:80 default_server;
server_name localhost;

index index.php index.html;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/html/public;

set $virtualdir "";
set $realdir "";

if ($request_uri ~ ^/([^/]*)/.*$ ) {
set $virtualdir /$1;
}

if (-d "$document_root$virtualdir") {
set $realdir "${virtualdir}";
}

location / {
try_files $uri $uri/ $realdir/index.php?$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass localhost:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}

Help if it's not difficult. The demo project is here https://github.com/Mavellol/kuber-nginx-php-mysql



My Answer:
you please provide more context or specify your question about Kubernetes?

Rate this post

5 of 5 based on 8754 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us