0

I have a knative setup with two worker nodes. After successfully testing helloworld-go sample program. I tried to wrote a simple C program that just prints environment variable "REQUEST_METHOD" and "QUERY_STRING". However pod status is "CrashLoopBackOff" and kubectl describe shows: " Readiness probe failed: Get http://192.168.203.181:8022/health: net/http: request canceled (Client.Timeout exceeded while awaiting headers)". I suspect something is wrong with my code. If possible please suggest what is wrong with my code. Dockerfile I used is this:

FROM gcc:4.9
COPY . /usr/src/test-c
WORKDIR /usr/src/test-c
RUN gcc -o test-c main.c
CMD ["./test-c"]

My C code for the same is:

#include <stdio.h>
#include <stdlib.h>

int main() {
   char* len_ = getenv("REQUEST_METHOD");
   printf("METHOD = %s, %s\n", len_, getenv("QUERY_STRING"));
}

My yaml file is:

apiVersion: serving.knative.dev/v1alpha1
kind: Service
metadata:
  name: helloworld-c
  namespace: default
spec:
  template:
    spec:
      containers:
        - image: docker.io/avinashkrc/helloworld-c:latest
          env:
            - name: TARGET
              value: "Go Sample"
avinashkrc
  • 93
  • 1
  • 9
  • what is the deployment yaml for your application using C language. You might have to remove `Readiness probe` from the deployment yaml. Because the `Readiness probe` check the health of your pod. In your case its hitting `http://192.168.203.181:8022/health` api. This api should exists in your C code or else you have to remove this `readiness probe` health api. – mchawre Aug 01 '19 at 16:35
  • You are not checking that `getenv` returns successfully. – Christian Gibbons Aug 01 '19 at 16:37
  • @mchawre Hi I updated yaml file in the question. Sorry I am new to all this knative/kubernetes. Can you please let me know how to either remove Readiness probe or implement this api in C. Do I have to implement server code in C? – avinashkrc Aug 01 '19 at 18:23
  • @ChristianGibbons Hi did tried that using if(len_) but problem with crashbackoff persists. – avinashkrc Aug 01 '19 at 18:24

1 Answers1

0

I am able to solve the problem using pistache for REST api (I guess any framework should work).

avinashkrc
  • 93
  • 1
  • 9