0
votes

PLEASE READ UPDATE 2

I have a very simple EventHubClient app. It will just listen to an EventHub messages.

I get it running with the Docker support given in Visual Studio 2017 (Linux Container).

But when I try to deploy it in Kubernetes, I get "Back-off restarting failed container"

C# Code:

public static void Main(string[] args)
{
    // Init Mapper
    AutoMapper.Mapper.Initialize(cfg =>
    {
        cfg.AddProfile<AiElementProfile>();
    });

    Console.WriteLine("Registering EventProcessor...");

    var eventProcessorHost = new EventProcessorHost(
        EventHubPath,
        ConsumerGroupName,
        EventHubConnectionString,
        AzureStorageConnectionString,
        ContainerName
    );

    // Registers the Event Processor Host and starts receiving messages
    eventProcessorHost.RegisterEventProcessorAsync<EventProcessor>();

    Console.WriteLine("Receiving. Press ENTER to stop worker.");
    Console.ReadLine();
}

Kubernetes Manifest file (.yaml):

apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: historysvc-deployment
spec:
  selector:
    matchLabels:
      app: historysvc
  replicas: 2
  template:
    metadata:
      labels:
        app: historysvc
    spec:
      containers:
      - name: historysvc
        image: vncont.azurecr.io/historysvc:v1
        ports:
        - containerPort: 80
      imagePullSecrets:
        - name: acr-auth

kubectl get pods:

   NAME                                     READY     STATUS             RESTARTS   AGE
    historysvc-deployment-558fc5649f-bln8f   0/1       CrashLoopBackOff   17         1h
    historysvc-deployment-558fc5649f-jgjvq   0/1       CrashLoopBackOff   17         1h

kubectl describe pod historysvc-deployment-558fc5649f-bln8f

Name:           historysvc-deployment-558fc5649f-bln8f
Namespace:      default
Node:           aks-nodepool1-81522366-0/10.240.0.4
Start Time:     Tue, 24 Jul 2018 10:15:37 +0200
Labels:         app=historysvc
                pod-template-hash=1149712059
Annotations:    <none>
Status:         Running
IP:             10.244.0.11
Controlled By:  ReplicaSet/historysvc-deployment-558fc5649f
Containers:
  historysvc:
    Container ID:   docker://59e66f1e6420146f6eca4f19e2801a4ee0435a34c7ac555a8d04f699a1497f35
    Image:          vncont.azurecr.io/historysvc:v1
    Image ID:       docker-pullable://vncont.azurecr.io/historysvc@sha256:636d81435bd421ec92a0b079c3841cbeb3ad410509a6e37b1ec673dc4ab8a444
    Port:           80/TCP
    State:          Terminated
      Reason:       Completed
      Exit Code:    0
      Started:      Tue, 24 Jul 2018 10:17:10 +0200
      Finished:     Tue, 24 Jul 2018 10:17:10 +0200
    Last State:     Terminated
      Reason:       Completed
      Exit Code:    0
      Started:      Tue, 24 Jul 2018 10:16:29 +0200
      Finished:     Tue, 24 Jul 2018 10:16:29 +0200
    Ready:          False
    Restart Count:  4
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-mt8mm (ro)
Conditions:
  Type           Status
  Initialized    True
  Ready          False
  PodScheduled   True
Volumes:
  default-token-mt8mm:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-mt8mm
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type     Reason                 Age              From                               Message
  ----     ------                 ----             ----                               -------
  Normal   Scheduled              1m               default-scheduler                  Successfully assigned historysvc-deployment-558fc5649f-bln8f to aks-nodepool1-81522366-0
  Normal   SuccessfulMountVolume  1m               kubelet, aks-nodepool1-81522366-0  MountVolume.SetUp succeeded for volume "default-token-mt8mm"
  Normal   Pulled                 8s (x5 over 1m)  kubelet, aks-nodepool1-81522366-0  Container image "vncont.azurecr.io/historysvc:v1" already present on machine
  Normal   Created                7s (x5 over 1m)  kubelet, aks-nodepool1-81522366-0  Created container
  Normal   Started                6s (x5 over 1m)  kubelet, aks-nodepool1-81522366-0  Started container
  Warning  BackOff                6s (x8 over 1m)  kubelet, aks-nodepool1-81522366-0  Back-off restarting failed container

What am I missing?


UPDATE 1

kubectl describe pod historysvc-deployment-558fc5649f-jgjvq

Name:           historysvc-deployment-558fc5649f-jgjvq
Namespace:      default
Node:           aks-nodepool1-81522366-0/10.240.0.4
Start Time:     Tue, 24 Jul 2018 10:15:37 +0200
Labels:         app=historysvc
                pod-template-hash=1149712059
Annotations:    <none>
Status:         Running
IP:             10.244.0.12
Controlled By:  ReplicaSet/historysvc-deployment-558fc5649f
Containers:
  historysvc:
    Container ID:   docker://ccf83bce216276450ed79d67fb4f8a66daa54cd424461762478ec62f7e592e30
    Image:          vncont.azurecr.io/historysvc:v1
    Image ID:       docker-pullable://vncont.azurecr.io/historysvc@sha256:636d81435bd421ec92a0b079c3841cbeb3ad410509a6e37b1ec673dc4ab8a444
    Port:           80/TCP
    State:          Waiting
      Reason:       CrashLoopBackOff
    Last State:     Terminated
      Reason:       Completed
      Exit Code:    0
      Started:      Wed, 25 Jul 2018 09:32:34 +0200
      Finished:     Wed, 25 Jul 2018 09:32:35 +0200
    Ready:          False
    Restart Count:  277
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-mt8mm (ro)
Conditions:
  Type           Status
  Initialized    True
  Ready          False
  PodScheduled   True
Volumes:
  default-token-mt8mm:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-mt8mm
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type     Reason   Age                  From                               Message
  ----     ------   ----                 ----                               -------
  Warning  BackOff  2m (x6238 over 23h)  kubelet, aks-nodepool1-81522366-0  Back-off restarting failed container

UPDATE 2

When I run it localy with:

docker run <image> 

it ends instantly (ignores the read line) (completes), which seems to be the problem.

I have to write

docker run -it <image> 

-it at the end for it to do the read line.

How does kubernetes runs the docker image? Where can I set that?

1
What does kubectl logs historysvc-deployment-558fc5649f-jgjvq show you? Also, what does kubectl get events show you about the deployment?Sage
Do you set the osType in the yaml file?Charles Xu
@Sage the command show no logs for both pods created by the replica set :(C3PO
@CharlesXu-MSFT please refer to my question (Kubernetes Manifest file (.yaml)). I didn't specify any OS and I think I never saw this on any example I looked at... :/C3PO
@Sage I did updated it with the kubectl describe pod historysvc-deployment-558fc5649f-jgjvqC3PO

1 Answers

3
votes

This can be done by attaching an argument to run with your deployment.

In your case the Kubernetes Manifest file (.yaml) should look like this:

apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: historysvc-deployment
spec:
  selector:
matchLabels:
  app: historysvc
  replicas: 2
  template:
metadata:
  labels:
    app: historysvc
spec:
  containers:
  - name: historysvc
    image: vncont.azurecr.io/historysvc:v1
    ports:
    - containerPort: 80
    args: ["-it"]
  imagePullSecrets:
    - name: acr-auth

You can find this explained in k8s docs inject-data-application/define-command-argument-container

When you create a Pod, you can define a command and arguments for the containers that run in the Pod. To define a command, include the command field in the configuration file. To define arguments for the command, include the args field in the configuration file. The command and arguments that you define cannot be changed after the Pod is created.

The command and arguments that you define in the configuration file override the default command and arguments provided by the container image. If you define args, but do not define a command, the default command is used with your new arguments.