#Deploy on kubernetes cluster with php Reverb command
9 messages · Page 1 of 1 (latest)
Firstly, you definitely have zero reason to be calling artisan serve during the deployment.
As for where to run the command: In a k8s env I work with, reverb is its own defined deployment within the backend k8s yaml, meaning there's a deployment defined for the backend php pods themselves, while also defining a reverb deployment with a single pod, that on start, runs the reverb command. We do this same thing for horizon. So "backend" actually defines 3 deployments for the given k8s namespace: php, reverb, horizon. Main point being, each backend deployment definition will use your same base php image and backend repo, but define pods and startup action differently.
Access wise, we use nginx and it's the reverse proxy to expose reverb externally
@spiral kayak, CMD against artisan serve or reverb:start isn't a good practice. by reading your "or", you can't invoke two blocking ops in one line and expect that both will run. when i said about good practice, if something fails on the command, then, the container will die and any trace of that will lost. So, here is supervisor works. ENTRYPOINT ["/usr/bin/supervisord", "-c", "/supervisor.conf"] and
nodaemon=true
[program:server]
directory=/server/bin
command=./Server
process_name=%(program_name)s_%(process_num)02d
numprocs=1
autostart=true
autorestart=true
startsecs=0
stdout_logfile=/server/stdout.log
stderr_logfile=/server/stdout.log
stdout_logfile_maxbytes=0
stderr_logfile_maxbytes=0
stopwaitsecs=10```
Hello, thx a lot !
And thx @scarlet lark, I would like to try to make only 1 deployment but if you have any example I would like to see it 🙂
So, @gleaming flume I should make something like :
supervisord.conf
[supervisord]
nodaemon=true
[program:nginx]
command=/usr/sbin/nginx -g 'daemon off;'
autostart=true
autorestart=true
stdout_logfile=/var/log/supervisor/nginx.log
stderr_logfile=/var/log/supervisor/nginx_error.log
[program:php-fpm]
command=/usr/sbin/php-fpm
autostart=true
autorestart=true
stdout_logfile=/var/log/supervisor/php-fpm.log
stderr_logfile=/var/log/supervisor/php-fpm_error.log
[program:reverb]
command=php /app/artisan reverb:start
autostart=true
autorestart=true
stdout_logfile=/var/log/supervisor/reverb.log
stderr_logfile=/var/log/supervisor/reverb_error.log
And add at the bottom of my dockerfile :
Dockerfile
ENTRYPOINT ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
But I kept getting **CrashLoopBackOff **on my pod.
But then for the configuration of the backend (Laravel) :
Should I do :
echo "REVERB_HOST=0.0.0.0" >> .env
echo "REVERB_PORT=6001" >> .env
echo "REVERB_SCHEME=http" >> .env
or
echo "REVERB_HOST=my.domain.net" >> .env
echo "REVERB_PORT=443" >> .env
echo "REVERB_SCHEME=https" >> .env
or the IP of my cluster or the domain or any other ip/port /scheme ?
And for the front(vuejs3) what should I do ? I tried :
echo "VITE_APP_API_URL=https://my.domain.net" > .env.production
echo "VITE_REVERB_APP_KEY=yk9f6goc0i1018sevmyt" >> .env.production
echo "VITE_REVERB_HOST=my.domain.net" >> .env.production
echo "VITE_REVERB_PORT=443" >> .env.production
echo "VITE_REVERB_SCHEME=https" >> .env.production
I have to admit that I am a bit lost between those documentations :
https://laravel.com/docs/11.x/sanctum
https://laravel.com/docs/11.x/broadcasting
https://laravel.com/docs/11.x/reverb
If you have any example of a SPA communicating with a laravel websocket with reverb it would be very helpfull
For my front I did :
import Echo from "laravel-echo";
import Pusher from "pusher-js";
import axios from "axios";
window.Pusher = Pusher;
const echo = new Echo({
broadcaster: "reverb",
key: import.meta.env.VITE_REVERB_APP_KEY,
wsHost: import.meta.env.VITE_REVERB_HOST,
wsPort: import.meta.env.VITE_REVERB_PORT ?? 80,
wssPort: import.meta.env.VITE_REVERB_PORT ?? 443,
forceTLS: (import.meta.env.VITE_REVERB_SCHEME ?? "https") === "https",
enabledTransports: ["ws", "wss"],
authorizer: (channel, options) => {
return {
authorize: (socketId, callback) => {
console.log("socketId");
console.log(socketId);
axios
.post("/api/broadcasting/auth", {
socket_id: socketId,
channel_name: channel.name,
})
.then((response) => {
callback(false, response.data);
console.log("response.data");
console.log(response.data);
})
.catch((error) => {
callback(true, error);
});
},
};
},
});
export default echo;
And I configured axios :
import axios from "axios";
axios.defaults.withCredentials = true;
axios.defaults.withXSRFToken = true;
axios.defaults.baseURL = import.meta.env.VITE_APP_API_URL;
the only error that i can see is, you're using the default supervisor.conf, did you change that? if you see my entrypoint, uses a supervisor.conf in root path, so i just move my conf.
The supervisord.conf that you provided doesn't seem to execute php artisan reverb:start.
Here is what I did :
[supervisord]
nodaemon=true
[program:nginx]
command=/usr/sbin/nginx -g 'daemon off;'
autostart=true
autorestart=true
stdout_logfile=/var/log/supervisor/nginx.log
stderr_logfile=/var/log/supervisor/nginx_error.log
[program:php-fpm]
command=/usr/sbin/php-fpm
autostart=true
autorestart=true
stdout_logfile=/var/log/supervisor/php-fpm.log
stderr_logfile=/var/log/supervisor/php-fpm_error.log
[program:reverb]
command=php /app/artisan reverb:start
autostart=true
autorestart=true
stdout_logfile=/var/log/supervisor/reverb.log
stderr_logfile=/var/log/supervisor/reverb_error.log
I should change it to the one you gaved ? :
[supervisord]
nodaemon=true
[program:server]
directory=/server/bin
command=./Server
process_name=%(program_name)s_%(process_num)02d
numprocs=1
autostart=true
autorestart=true
startsecs=0
stdout_logfile=/server/stdout.log
stderr_logfile=/server/stdout.log
stdout_logfile_maxbytes=0
stderr_logfile_maxbytes=0
stopwaitsecs=10
What if I am only adding this to start reverb after 60 seconds ?
RUN echo "@reboot sleep 60 && php /app/artisan reverb:start >> /app/storage/logs/laravel.log 2>&1" >> /var/spool/cron/crontabs/root
it seems that I don't have any error and it does actually start reverb.
But I still don't know what IP and port I have to put.
Currently I tried :
echo "REVERB_HOST=api.springcard.net" >> .env
echo "REVERB_PORT=443" >> .env
echo "REVERB_SCHEME=https" >> .env
But I got the following error :
Given URI "tcp://api.springcard.net:443" does not contain a valid host IP (
EINVAL)