CyCoreSystems / asterisk-k8s-demo

Demo of scalable Asterisk on Kubernetes
Apache License 2.0
158 stars 72 forks source link

Kamailio.cfg #2

Closed juansalvatella closed 6 years ago

juansalvatella commented 6 years ago

Hi! I have watched your Astricon conference and I think it's amazing what you have been able to achieve with VoIP and Kubernetes. I want to get hands-on practice on the live-demo but Kamailio won't start and that's because its configuration file is empty. What was the configuration that you used for the demo? Thanks!

Ulexus commented 6 years ago

I presume you found the problem, but just in case, the key to the kamailio config is that it needs to find its IP address. If those variables aren't set, confd will fail to generate the configuration, and kamailio will not start. The entrypoint.sh script in the example defaults to GCE's (including GKE) method, but AWS is in there and commented out. Other environments will have other mechanisms.

The variable names were chosen in line with CoreOS's choices, so if you are running a CoreOS/ContainerLinux cluster, they will probably just work (as long as you pass them in).

juansalvatella commented 6 years ago

I closed the issue because I realised that it was necessary to deploy it on GCE or in AWS but after doing so, I am still having the same issue. I have deployed all the components on a cluster in GKE.

kubectl get pods

NAME READY STATUS RESTARTS AGE asterisk-beta-3582577866-kl2m0 3/3 Running 1 1h app-416630557-pwjm0 1/1 Running 0 10m kamailio-m68f8 2/3 CrashLoopBackOff 9 24m nats-3986961018-f45g7 1/1 Running 0 1h

NOTE: I renamed the asterisk container to asterisk-beta because I had another asterisk deployment running. That shouldn't be the problem, right?

kubectl logs kamailio-m68f8 kamailio

2018-02-28T17:30:07Z gke-kitchen-line-pro-default-pool-97db87fb-637q confd[13]: INFO Backend set to env 2018-02-28T17:30:07Z gke-kitchen-line-pro-default-pool-97db87fb-637q confd[13]: INFO Starting confd 2018-02-28T17:30:07Z gke-kitchen-line-pro-default-pool-97db87fb-637q confd[13]: INFO Backend nodes set to 2018-02-28T17:30:07Z gke-kitchen-line-pro-default-pool-97db87fb-637q confd[13]: INFO /etc/kamailio/kamailio.cfg has md5sum 17481ad2235ef9698da57c6e90d5ac2b should be e5e440bdb63b2bd690f9b7338ed11912 2018-02-28T17:30:07Z gke-kitchen-line-pro-default-pool-97db87fb-637q confd[13]: INFO Target config /etc/kamailio/kamailio.cfg out of sync 2018-02-28T17:30:07Z gke-kitchen-line-pro-default-pool-97db87fb-637q confd[13]: INFO Target config /etc/kamailio/kamailio.cfg has been updated 0(1) : [cfg.y:3368]: yyerror_at(): parse error in config file /etc/kamailio/kamailio.cfg, line 35, column 65-71: syntax error 0(1) : [cfg.y:3368]: yyerror_at(): parse error in config file /etc/kamailio/kamailio.cfg, line 35, column 65-71: invalid host or interface name 0(1) : [cfg.y:3371]: yyerror_at(): parse error in config file /etc/kamailio/kamailio.cfg, line 35, column 72:

Update 1: After some research and debugging, the environment variables are picked up correctly

PRIVATE_IPV4: 10.156.0.2 PRIVATE_HOSTNAME: gke-kitchen-line-pro-default-pool-97db87fb-637q.c.kitchen-line.internal

and the error seems to be pointing to this line of the config template:

alias=sip.astricon.cycore.io {{getv "/public/ipv4"}} {{getv "/public/hostname"}}

Any hints?

Ulexus commented 6 years ago

Those substitutions are using PUBLIC_HOSTNAME and PUBLIC_IPV4, not PRIVATE_HOSTNAME and PRIVATE_IPV4. The script should generate them properly, though... did you modify the script or mis-type the variable names here?

juansalvatella commented 6 years ago

Thanks for your quick support on this. You are right, I mistyped the variable names. I have modified the docker-entrypoint script to show if the value of the variables (PUBLIC_IPV4, PRIVATE_IPV4, PUBLIC_HOSTNAME) is being picked up and it does.

Is there a way to see the actual kamailio.cfg file that's making the container fail? I would usually run bash on the container to see the file but since it's creation fails I am unable to do so.

Ulexus commented 6 years ago

Not very easily. Kubernetes is going to clean up the old container pretty quickly. You could always modify the entrypoint script to cat the resulting file out, which would then be captured by the log.

juansalvatella commented 6 years ago

Great tip! I did so and line 35 of the config file (the one with the error) is as follows:

alias=sip.astricon.cycore.io 35.198.71.228 gke-kitchen-line-pro-default-pool-97db87fb-637q.c.kitchen-line.internal

It should be right, right?

Ulexus commented 6 years ago

It does look to be correct, yes. It is still failing on that line?

juansalvatella commented 6 years ago

Yes. Find attached the whole config file kamailio.txt and this is the error trace:

0(1) CRITICAL: [core/cfg.y:3411]: yyerror_at(): parse error in config file /etc/kamailio/kamailio.cfg, line 35, column 65-71: syntax error 0(1) CRITICAL: [core/cfg.y:3411]: yyerror_at(): parse error in config file /etc/kamailio/kamailio.cfg, line 35, column 65-71: invalid host or interface name 0(1) CRITICAL: [core/cfg.y:3414]: yyerror_at(): parse error in config file /etc/kamailio/kamailio.cfg, line 35, column 72: ERROR: bad config file (3 errors)

Ulexus commented 6 years ago

That's very curious. Kamailio is triggering on the word "default" for some reason. If you modify just that... make it "dfault" instead of "default", it works. That's most curious, and I don't think that has anything whatever to do with this k8s setup.

On the plus side, you don't need the host name in there as an alias unless you use it with the clients connecting to the kamailio box. I believe everything in the demo just uses the IP, so you should be able to remove the $PUBLIC_HOSTNAME from the template and be fine.

juansalvatella commented 6 years ago

Nice! That made the trick but unfortunately another issue has shown up.

2018-03-02T00:02:17Z gke-kitchen-line-pro-default-pool-97db87fb-637q confd[13]: INFO Backend set to env 2018-03-02T00:02:17Z gke-kitchen-line-pro-default-pool-97db87fb-637q confd[13]: INFO Starting confd 2018-03-02T00:02:17Z gke-kitchen-line-pro-default-pool-97db87fb-637q confd[13]: INFO Backend nodes set to 2018-03-02T00:02:17Z gke-kitchen-line-pro-default-pool-97db87fb-637q confd[13]: INFO /etc/kamailio/kamailio.cfg has md5sum 17481ad2235ef9698da57c6e90d5ac2b should be 6bc020a98538cf5080169609b92b6b8d 2018-03-02T00:02:17Z gke-kitchen-line-pro-default-pool-97db87fb-637q confd[13]: INFO Target config /etc/kamailio/kamailio.cfg out of sync 2018-03-02T00:02:17Z gke-kitchen-line-pro-default-pool-97db87fb-637q confd[13]: INFO Target config /etc/kamailio/kamailio.cfg has been updated 0(1) ERROR: [core/sr_module.c:571]: load_module(): could not find module in </usr/local/lib64/kamailio/modules:/usr/local/lib64/kamailio/modules_k:/usr/lib/x86_64-linux-gnu/kamailio/modules/> 0(1) CRITICAL: [core/cfg.y:3411]: yyerror_at(): parse error in config file /etc/kamailio/modules.k, line 9, column 12-20: failed to load module 0(1) ERROR: [core/modparam.c:152]: set_mod_param_regex(): No module matching found 0(1) CRITICAL: [core/cfg.y:3414]: yyerror_at(): parse error in config file /etc/kamailio/module_cfg/mi_fifo.k, line 7, column 54: Can't set module parameter 0(1) INFO: pv [pv_shv.c:60]: shvar_init_locks(): locks array size 16 0(1) ERROR: [core/modparam.c:141]: set_mod_param_regex(): parameter of type <2> not found in module 0(1) CRITICAL: [core/cfg.y:3414]: yyerror_at(): parse error in config file /etc/kamailio/module_cfg/utils.k, line 2, column 42: Can't set module parameter ERROR: bad config file (3 errors) 0(1) INFO: [core/sctp_core.c:53]: sctp_core_destroy(): SCTP API not initialized loading modules under config path: /usr/local/lib64/kamailio/modules:/usr/local/lib64/kamailio/modules_k:/usr/lib/x86_64-linux-gnu/kamailio/modules/

Ulexus commented 6 years ago

Ah, obviously I need to update that Dockerfile. That was due to a change in the debian kamailio packages, if I recall correctly. Let me see if I can track it down.

Ulexus commented 6 years ago

mi_fifo is missing from the new Debian packages, but that's fine, because we shouldn't be using it.

juansalvatella commented 6 years ago

Thanks Sean! You’ve been of amazing help. mi_fifo has been fixed but I still need to find a way to fix the other 2 criticals. If I do, I will write back!

Ulexus commented 6 years ago

Are you sure you pulled the latest version? Both of those should be commented out.

juansalvatella commented 6 years ago

Yes, the only difference is with the mi_fifo module but this 2 seem unrelated:

0(1) INFO: pv [pv_shv.c:60]: shvar_init_locks(): locks array size 16 0(1) ERROR: [core/modparam.c:141]: set_mod_param_regex(): parameter of type <2> not found in module 0(1) CRITICAL: [core/cfg.y:3414]: yyerror_at(): parse error in config file /etc/kamailio/module_cfg/utils.k, line 2, column 42: Can't set module parameter ERROR: bad config file (1 errors) 0(1) INFO: [core/sctp_core.c:53]: sctp_core_destroy(): SCTP API not initialized loading modules under config path: /usr/local/lib64/kamailio/modules:/usr/local/lib64/kamailio/modules_k:/usr/lib/x86_64-linux-gnu/kamailio/modules/

juansalvatella commented 6 years ago

It's working now! I commented the modparam("utils", "http_query_timeout", 1) line in utils.k and the container is running.