CyCoreSystems / asterisk-k8s-demo

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

bad config file #1

Closed isaldarriaga closed 7 years ago

isaldarriaga commented 7 years ago

I labeled 1 node with cloud.google.com/gke-nodepool=pool-kamailio

kubectl apply -f 01-nats.yaml

kubectl label nodes $(kubectl get nodes | grep gke | awk -F ' ' 'NR==1{print $1}') cloud.google.com/gke-nodepool=pool-kamailio --overwrite

kubectl apply -f kamailio.yaml
kubectl apply -f asterisk.yaml
kubectl apply -f app.yaml

so the DaemonSet launches the pod in one of the cluster nodes.

The "kamailio" container in the kamailio-xxx pod is failing though:

$ kubectl get po

NAME                            READY     STATUS             RESTARTS   AGE
asterisk-1744660152-8msl9       3/3       Running            13         1d
app-3527931237-jg899   1/1       Running            0          4h
kamailio-t9bjr                  2/3       CrashLoopBackOff   6          10m

The error:

$ kubectl logs kamailio-t9bjr -c kamailio

2017-08-24T00:18:25Z gke-foo-cluster-default-pool-72561ba1-992g confd[13]: INFO Backend set to env
2017-08-24T00:18:25Z gke-foo-cluster-default-pool-72561ba1-992g confd[13]: INFO Starting confd
2017-08-24T00:18:25Z gke-foo-cluster-default-pool-72561ba1-992g confd[13]: INFO Backend nodes set to 
2017-08-24T00:18:25Z gke-foo-cluster-default-pool-72561ba1-992g confd[13]: INFO /etc/kamailio/kamailio.cfg has md5sum 17481ad2235ef9698da57c6e90d5ac2b should be 469d897d2dde81f6320357a41712c89f
2017-08-24T00:18:25Z gke-foo-cluster-default-pool-72561ba1-992g confd[13]: INFO Target config /etc/kamailio/kamailio.cfg out of sync
2017-08-24T00:18:25Z gke-foo-cluster-default-pool-72561ba1-992g confd[13]: INFO Target config /etc/kamailio/kamailio.cfg has been updated
 0(1) : <core> [cfg.y:3368]: yyerror_at(): parse error in config file /etc/kamailio/kamailio.cfg, line 35, column 68-74: syntax error
 0(1) : <core> [cfg.y:3368]: yyerror_at(): parse error in config file /etc/kamailio/kamailio.cfg, line 35, column 68-74: invalid host or interface name
 0(1) : <core> [cfg.y:3371]: yyerror_at(): parse error in config file /etc/kamailio/kamailio.cfg, line 35, column 75: 
ERROR: bad config file (3 errors)

Looks like the software expects a specific checksum on the configuration file, then replace it and fails with the default values.

Any workaround?

Ulexus commented 7 years ago

It's complaining about line 35 being invalid. Line 35 is the alias line, which means you're almost certainly failing the hostname or public IP address lookups in the entrypoint script.

I would run, manually, those curl commands and make sure you are getting reasonable results. Failing that, modify the entrypoint script to echo out the resulting environment variables.

isaldarriaga commented 7 years ago

The lookups seems to be working fine from inside a running container in the kamailio pod (i havent' printed the vars from the entrypoint yet):

$ kubectl exec -it kamailio-t9bjr -c rtpproxy -- sh

/ # curl -H 'Metadata-Flavor: Google' http://metadata.google.internal/computeMetadata/v1/instance/network-interfaces/0/access-configs/0/external-ip
35.xxx.191.224

/ # curl -H 'Metadata-Flavor: Google' http://metadata.google.internal/computeMetadata/v1/instance/network-interfaces/0/ip
10.138.0.2

/ # curl -H 'Metadata-Flavor: Google' http://metadata.google.internal/computeMetadata/v1/instance/hostname
gke-foo-cluster-default-pool-72561ba1-992g.c.foo-project.internal

/ # exit

I'm trying to understand better the alias code here.

The kamailio.conf is a dummy file in the source code, but as far as i understand it's copied at runtime from live-demo/kamailio/confd-env/templates/kamailio.cfg.tmpl, right?

(evidenced in the log entry: 2017-08-24T00:18:25Z gke-foo-cluster-default-pool-72561ba1-992g confd[13]: INFO Target config /etc/kamailio/kamailio.cfg has been updated)

In the kamailio.cfg.tmpl line (35) we have:

## 
# Manual addition of aliased hostnames held by the local server.  This
# adds hostname/port tuples to the list of destinations that match the
# 'myself' keyword and are considered local by loose_route().  It is 
# necessary to provide both the hostname and the port (e.g. alias=host:5060)
# for this to work properly.  These entries supplement local aliases
# automatically discovered in /etc/hosts.  Multiple 'alias' entries may 
# be present.

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

According to the document we need a tuple hostname:port, but only the ip is returned by the curl command. Is this relevant?

Ulexus commented 7 years ago

Aha, you're exactly correct. They do need the port. I wonder why that is missing... oh, well, yes. It is obviously wrong, and it needs the port number

isaldarriaga commented 7 years ago

I changed the alias line in kamailio.cfg.tmpl :

alias="{{getv "/public/hostname"}}:5060"

since GCE FQDNs have dashes, the alias need to be enclosed in double quotes too according to the kamailio specs.

Now the container starts up.