Ingress configuration as String with Flink statefun - apache-flink
What I am trying to do
Once followed the python walkthrough I am trying to modify module.yaml file so ingress and egress is not Protobuf but String. I have not really modify most of the files, only module.yaml trying to configure for string ingress and greeter.py to not take into account either state or protobuf messages and only to print the input received from the ingress.
The architecture of the project has not being changed:
$ tree statefun-walkthrough
statefun-walkthrough
├── Dockerfile
├── docker-compose.yml
├── generator
│ ├── Dockerfile
│ ├── event-generator.py
│ └── messages_pb2.py
├── greeter
│ ├── Dockerfile
│ ├── greeter.py
│ ├── messages.proto
│ ├── messages_pb2.py
│ └── requirements.txt
└── module.yaml
The used configuration files and python application:
docker-compose.yml
version: "2.1"
services:
zookeeper:
image: wurstmeister/zookeeper
ports:
- "2181:2181"
kafka-broker:
image: wurstmeister/kafka:2.12-2.0.1
ports:
- "9092:9092"
environment:
HOSTNAME_COMMAND: "route -n | awk '/UG[ \t]/{print $$2}'"
KAFKA_CREATE_TOPICS: "names:1:1,greetings:1:1"
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
depends_on:
- zookeeper
volumes:
- /var/run/docker.sock:/var/run/docker.sock
master: # for flink-statefun
build:
context: .
expose:
- "6123"
ports:
- "8081:8081"
environment:
- ROLE=master
- MASTER_HOST=master
volumes:
- ./checkpoint-dir:/checkpoint-dir
worker: # for flink-statefun
build:
context: .
expose:
- "6121"
- "6122"
depends_on:
- master
- kafka-broker
links:
- "master:master"
- "kafka-broker:kafka-broker"
environment:
- ROLE=worker
- MASTER_HOST=master
volumes:
- ./checkpoint-dir:/checkpoint-dir
python-worker: # greeter application
build:
context: ./greeter
expose:
- "8000"
event-generator: # reading and writting in kafka topic
build:
context: generator
dockerfile: Dockerfile
depends_on:
- kafka-broker
module.yaml
version: "1.0"
module:
meta:
type: remote
spec:
functions:
- function:
meta:
kind: http
type: example/greeter
spec:
endpoint: http://python-worker:8000/statefun
maxNumBatchRequests: 500
timeout: 2min
ingresses:
- ingress:
meta:
type: statefun.kafka.io/ingress
id: example/names
spec:
address: kafka-broker:9092
consumerGroupId: my-group-id
topics:
- topic: names
valueType: io.statefun.types/string
targets:
- example/greeter
egresses:
- egress:
meta:
type: statefun.kafka.io/egress
id: example/greets
spec:
address: kafka-broker:9092
deliverySemantic:
type: exactly-once
transactionTimeoutMillis: 100000
greeter.py
from statefun import StatefulFunctions
from statefun import RequestReplyHandler
from statefun import kafka_egress_record
functions = StatefulFunctions()
#functions.bind("example/greeter")
def greet(context, message):
print(type(message), message)
handler = RequestReplyHandler(functions)
#
# Serve the endpoint
#
from flask import request
from flask import make_response
from flask import Flask
app = Flask(__name__)
#app.route('/statefun', methods=['POST'])
def handle():
response_data = handler(request.data)
response = make_response(response_data)
response.headers.set('Content-Type', 'application/octet-stream')
return response
if __name__ == "__main__":
app.run()
The error
After running docker-compose up -d --build flink master stops with the next error:
2022-02-14 18:11:14,795 INFO org.apache.flink.runtime.entrypoint.ClusterEntrypoint [] - Shutting StatefulFunctionsClusterEntryPoint down with application status FAILED. Diagnostics org.apache.flink.util.FlinkException: Could not create the DispatcherResourceManagerComponent.
at org.apache.flink.runtime.entrypoint.component.DefaultDispatcherResourceManagerComponentFactory.create(DefaultDispatcherResourceManagerComponentFactory.java:256)
at org.apache.flink.runtime.entrypoint.ClusterEntrypoint.runCluster(ClusterEntrypoint.java:219)
at org.apache.flink.runtime.entrypoint.ClusterEntrypoint.lambda$startCluster$0(ClusterEntrypoint.java:172)
at org.apache.flink.runtime.security.contexts.NoOpSecurityContext.runSecured(NoOpSecurityContext.java:30)
at org.apache.flink.runtime.entrypoint.ClusterEntrypoint.startCluster(ClusterEntrypoint.java:171)
at org.apache.flink.runtime.entrypoint.ClusterEntrypoint.runClusterEntrypoint(ClusterEntrypoint.java:520)
at org.apache.flink.statefun.flink.launcher.StatefulFunctionsClusterEntryPoint.main(StatefulFunctionsClusterEntryPoint.java:99)
Caused by: org.apache.flink.util.FlinkRuntimeException: Could not retrieve the JobGraph.
at org.apache.flink.runtime.dispatcher.runner.JobDispatcherLeaderProcessFactoryFactory.createFactory(JobDispatcherLeaderProcessFactoryFactory.java:57)
at org.apache.flink.runtime.dispatcher.runner.DefaultDispatcherRunnerFactory.createDispatcherRunner(DefaultDispatcherRunnerFactory.java:51)
at org.apache.flink.runtime.entrypoint.component.DefaultDispatcherResourceManagerComponentFactory.create(DefaultDispatcherResourceManagerComponentFactory.java:194)
... 6 more
Caused by: org.apache.flink.util.FlinkException: Could not create the JobGraph from the provided user code jar.
at org.apache.flink.statefun.flink.launcher.StatefulFunctionsJobGraphRetriever.retrieveJobGraph(StatefulFunctionsJobGraphRetriever.java:107)
at org.apache.flink.runtime.dispatcher.runner.JobDispatcherLeaderProcessFactoryFactory.createFactory(JobDispatcherLeaderProcessFactoryFactory.java:55)
... 8 more
Caused by: org.apache.flink.client.program.ProgramInvocationException: The main method caused an error: There are no routers defined.
at org.apache.flink.client.program.PackagedProgram.callMainMethod(PackagedProgram.java:302)
at org.apache.flink.client.program.PackagedProgram.invokeInteractiveModeForExecution(PackagedProgram.java:198)
at org.apache.flink.client.program.PackagedProgramUtils.getPipelineFromProgram(PackagedProgramUtils.java:150)
at org.apache.flink.client.program.PackagedProgramUtils.createJobGraph(PackagedProgramUtils.java:77)
at org.apache.flink.statefun.flink.launcher.StatefulFunctionsJobGraphRetriever.retrieveJobGraph(StatefulFunctionsJobGraphRetriever.java:101)
... 9 more
Caused by: java.lang.IllegalStateException: There are no routers defined.
at org.apache.flink.statefun.flink.core.StatefulFunctionsUniverseValidator.validate(StatefulFunctionsUniverseValidator.java:31)
at org.apache.flink.statefun.flink.core.StatefulFunctionsJob.main(StatefulFunctionsJob.java:76)
at org.apache.flink.statefun.flink.core.StatefulFunctionsJob.main(StatefulFunctionsJob.java:52)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.flink.client.program.PackagedProgram.callMainMethod(PackagedProgram.java:288)
... 13 more
I do not know if this Exception Caused by: org.apache.flink.client.program.ProgramInvocationException: The main method caused an error: There are no routers defined. is the main problem and why is it happening.
Related
How to run init.sql using docker-compose.yml?
I'm creating a SQL server in docker container using docker-compose.yml, but i can't execute my init.sql when i run docker Code from docker-compose.yml version: "3.9" services: mssql-service: image: mcr.microsoft.com/mssql/server:2019-latest # Or whatever version you want container_name: mssql restart: unless-stopped ports: - "1433:1433" environment: - ACCEPT_EULA=Y - SA_PASSWORD=my_password - MSSQL_PID=Developer - MSSQL_AGENT_ENABLED=True volumes: - sqlvolume:/var/opt/mssql - C:/Users/joel_/Documents/GitLab/Emaresa/apps/api/init.sql:/docker-entrypoint-initdb.d/init.sql code from init.sql USE master; GO IF NOT EXISTS (SELECT name FROM sys.databases WHERE name = 'my_database') CREATE DATABASE my_database; GO my folder: project/ │ .gitignore │ alembic.ini │ database.env │ docker-command.bash │ docker-compose.yml │ init.sql │ poetry.lock │ pyproject.toml hope someone help me with this because i didn't figure it out how to execute init.sql and create my_database
Traefik Django & React setup
Recently I came across server configuration using GitLab CI/CD and docker-compose, I have two separated repositories one for Django and the other for React JS on Gitlab. The Django Repo contains the following production.yml file: version: '3' volumes: production_postgres_data: {} production_postgres_data_backups: {} production_traefik: {} services: django: &django build: context: . dockerfile: ./compose/production/django/Dockerfile image: one_sell_production_django platform: linux/x86_64 expose: # new - 5000 depends_on: - postgres - redis env_file: - ./.envs/.production/.django - ./.envs/.production/.postgres command: /start labels: # new - "traefik.enable=true" - "traefik.http.routers.django.rule=Host(`core.lwe.local`)" postgres: build: context: . dockerfile: ./compose/production/postgres/Dockerfile image: one_sell_production_postgres expose: - 5432 volumes: - production_postgres_data:/var/lib/postgresql/data:Z - production_postgres_data_backups:/backups:z env_file: - ./.envs/.production/.postgres traefik: # new image: traefik:v2.2 ports: - 80:80 - 8081:8080 volumes: - "./compose/production/traefik/traefik.dev.toml:/etc/traefik/traefik.toml" - "/var/run/docker.sock:/var/run/docker.sock:ro" redis: image: redis:6 This is work perfectly using the Traefik, I have also the following code for React JS repo: version: '3.8' services: frontend: build: context: ./ dockerfile: Dockerfile expose: - 3000 labels: # new - "traefik.enable=true" - "traefik.http.routers.django.rule=Host(`lwe.local`)" restart: 'always' env_file: - .env Now I don't know how to connect both Django and React Js Repo using the Traefik and also how the CI/CD configuration should be, the following is the CI/CD configuration for Django Repo (I omitted unnecessary info and just include the deploy stage): deploy: stage: deploy tags: - docker when: always before_script: - mkdir -p .envs/.production/ - touch .envs/.production/.django - touch .envs/.production/.postgres - touch .env - chmod +x ./setup_env.sh - sh setup_env.sh - less .envs/.production/.django - less .envs/.production/.postgres - docker-compose -f production.yml build - docker-compose -f production.yml run --rm django python manage.py migrate script: - docker-compose -f local.yml up -d
Dockerfile entrypoint in Kubernetes not executed
I've a docker container based ReactJS based app, a shell script is defined in docker image as the ENTRYPOINT, and I'm able to use docker run image-name successfully. Now the task is to use this docker image for Kubernetes deployment using standard deployment.yaml file templates, something like following # Deployment file apiVersion: apps/v1 kind: Deployment metadata: name: my-app labels: app: my-app spec: replicas: 1 selector: matchLabels: app: my-app template: metadata: labels: app: my-app spec: terminationGracePeriodSeconds: 120 containers: - name: my-app imagePullPolicy: Always image: my-docker-image command: ["/bin/bash"] args: ["-c","./entrypoint.sh;while true; do echo hello; sleep 10;done"] kind: Service apiVersion: v1 metadata: name: my-service spec: type: NodePort selector: app: my-app ports: - port: 3000 targetPort: 3000 protocol: TCP nodePort: 31110 spec: rules: - http: paths: - path: / pathType: Prefix backend: service: name: my-service port: number: 3000 when I do kubectl apply -f mydeployment.yaml, its creating required pod, but the entrypoint.sh script is not being executed upon creation of pod unlike direct running of docker image. Can someone please help in sharing what is wrong with above yaml file, am I missing or doing something incorrectly? I also tried direclty call npm run start in command [] within yaml but no luck. I can enter in pod container using kubectl exec but I don't see react app running, I can manually execute entrypoint.sh and see the required output in browser. Edit: Adding kubectl logs and describe output logs: when I removed command/args from yaml and applied deploy.yaml, I get following logs as is, until starting the dev server line, there's nothing beyond that. > myapp start /app > react-scripts start ℹ 「wds」: Project is running at http://x.x.x.x/ ℹ 「wds」: webpack output is served from ℹ 「wds」: Content not from webpack is served from /app/public ℹ 「wds」: 404s will fallback to / Starting the development server... Describe output Name: my-view-85b597db55-72jr8 Namespace: default Priority: 0 Node: my-node/x.x.x.x Start Time: Fri, 16 Apr 2021 11:13:20 +0800 Labels: app=my-app pod-template-hash=85b597db55 Annotations: cni.projectcalico.org/podIP: x.x.x.x/xx cni.projectcalico.org/podIPs: x.x.x.x/xx Status: Running IP: x.x.x.x IPs: IP: x.x.x.x Controlled By: ReplicaSet/my-view-container-85b597db55 Containers: my-ui-container: Container ID: containerd://671a1db809b7f583b2f3702e06cee3477ab1412d1e4aa8ac93106d8583f2c5b6 Image: my-docker-image Image ID: my-docker-image#sha256:29f5fc74aa0302039c37d14201f5c85bc8278fbeb7d70daa2d867b7faa6d6770 Port: <none> Host Port: <none> State: Terminated Reason: Completed Exit Code: 0 Started: Fri, 16 Apr 2021 11:13:41 +0800 Finished: Fri, 16 Apr 2021 11:13:43 +0800 Last State: Terminated Reason: Completed Exit Code: 0 Started: Fri, 16 Apr 2021 11:13:24 +0800 Finished: Fri, 16 Apr 2021 11:13:26 +0800 Ready: False Restart Count: 2 Environment: MY_ENVIRONMENT_NAME: TEST_ENV MY_SERVICE_NAME: my-view-service MY_SERVICE_MAIN_PORT: 3000 Mounts: /var/run/secrets/kubernetes.io/serviceaccount from default-token-9z8bw (ro) Conditions: Type Status Initialized True Ready False ContainersReady False PodScheduled True Volumes: default-token-9z8bw: Type: Secret (a volume populated by a Secret) SecretName: default-token-9z8bw Optional: false QoS Class: BestEffort Node-Selectors: <none> Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s node.kubernetes.io/unreachable:NoExecute op=Exists for 300s Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Scheduled 32s default-scheduler Successfully assigned default/my-view-container-85b597db55-72jr8 to my-host Normal Pulled 31s kubelet Successfully pulled image "my-docker-image" in 184.743641ms Normal Pulled 28s kubelet Successfully pulled image "my-docker-image" in 252.382942ms Normal Pulling 11s (x3 over 31s) kubelet Pulling image "my-docker-image" Normal Pulled 11s kubelet Successfully pulled image "my-docker-image" in 211.2478ms Normal Created 11s (x3 over 31s) kubelet Created container my-view-container Normal Started 11s (x3 over 31s) kubelet Started container my-view-container Warning BackOff 8s (x2 over 26s) kubelet Back-off restarting failed container and my entrypoint.sh is #!/bin/bash ( export REACT_APP_ENV_VAR=env_var_value;npm run start ) exec "$#"
When you write this in a pod description: containers: - name: my-app imagePullPolicy: Always image: my-docker-image command: ["/bin/bash"] args: ["-c","./entrypoint.sh;while true; do echo hello; sleep 10;done"] The command argument overrides the container ENTRYPOINT. The above is roughly equivalent to: docker run --entrypoint /bin/bash my-docker-image ...args here... If you want to use the ENTRYPOINT from the image, then just set args.
I figured out the solution finally, I included following options in yaml under spec section and removed command/args as mentioned by above comments. Hopefully it'll be useful to anyone facing this issue. spec: replicas: 1 selector: matchLabels: app: my-app template: metadata: labels: app: my-app spec: terminationGracePeriodSeconds: 120 containers: - name: my-app imagePullPolicy: Always image: my-docker-image stdin: true tty: true
400 Bad Request The plain HTTP request was sent to HTTPS port, while Deploying Django to AWS with Docker and Let's Encrypt
I am following the "Django on Docker Series" series by testdrivenio(https://testdriven.io/blog/django-docker-https-aws/) for deploying a project into a new domain. I am using Django as backend but when I try to access the backend url via the port it showing via docker ps command i.e., http://0.0.0.0:443/ I get the following error, This is the docker-compose file I am using version: '3.7' services: web: build: context: ./myprojectname dockerfile: Dockerfile.staging image: 789497322711.dkr.ecr.us-east-3.amazonaws.com/myprojectname-staging:web command: gunicorn myprojectname.wsgi:application --bind 0.0.0.0:8005 volumes: - static_volume:/home/myprojectname_staging/web/static - media_volume:/home/myprojectname_staging/web/media expose: - 8000 env_file: - ./.env.staging frontendimage: container_name: frontendimage image: 789497322711.dkr.ecr.us-east-3.amazonaws.com/myprojectname-staging:frontendimage stdin_open: true build: context: . dockerfile: frontend/Dockerfile.staging # volumes: # - type: bind # source: ./frontend # target: /usr/src/frontend # - '.:/usr/src/frontend' # - '/usr/src/frontend/node_modules' ports: - '1337:30' environment: - CHOKIDAR_USEPOLLING=true depends_on: - web nginx-proxy: container_name: nginx-proxy build: ./myprojectname/nginx image: 789497322711.dkr.ecr.us-east-3.amazonaws.com/myprojectname-staging:nginx-proxy restart: always ports: - 443:443 - 80:80 volumes: - static_volume:/home/myprojectname_staging/web/staticfiles - media_volume:/home/myprojectname_staging/web/mediafiles - certs:/etc/nginx/certs - html:/usr/share/nginx/html - vhost:/etc/nginx/vhost.d - /var/run/docker.sock:/tmp/docker.sock:ro depends_on: - web nginx-proxy-letsencrypt: image: jrcs/letsencrypt-nginx-proxy-companion env_file: - .env.staging.proxy-companion volumes: - /var/run/docker.sock:/var/run/docker.sock:ro - certs:/etc/nginx/certs - html:/usr/share/nginx/html - vhost:/etc/nginx/vhost.d depends_on: - nginx-proxy volumes: static_volume: media_volume: certs: html: vhost: My Nginx directory └── nginx ├── Dockerfile ├── custom.conf └── vhost.d └── default Dockerfile FROM jwilder/nginx-proxy COPY vhost.d/default /etc/nginx/vhost.d/default COPY custom.conf /etc/nginx/conf.d/custom.conf custom.conf client_max_body_size 10M; default server { listen 80; listen 443 default ssl; } location /static/ { alias /home/myprojectname_staging/web/static/; add_header Access-Control-Allow-Origin *; } location /media/ { alias /home/myprojectname_staging/web/media/; add_header Access-Control-Allow-Origin *; } What should be my next course of action?
MongoDb in a container seed with multiple collections
I'm trying to feed my mongo running in a container with existing collections living outside the container. docker-compose.yml looks like this: version: "3" services: webapi: image: webapp:develop container_name: web_api build: args: buildconfig: Debug context: ../src/api dockerfile: Dockerfile environment: - ASPNETCORE_ENVIRONMENT=Development - ASPNETCORE_URLS=http://+:5003 ports: - "5003:5003" depends_on: - mongodb mongodb: image: mongo:latest container_name: mongodb ports: - "27017:27017" mongo-seed: build: ./mongo-seed links: - mongodb mongo-seed/Dockerfile: FROM mongo COPY initA.json /initA.json CMD mongoimport --host mongodb --db Database --collection A --type json --file /initA.json --jsonArray --mode merge FROM mongo COPY initB.json /initB.json CMD mongoimport --host mongodb --db TestListDb --collection B --type json --file /initB.json --jsonArray --mode merge But this doesn't do the trick as it overwrites the database with the last collection, so maintains only 'B' collection in this case. How can I import multiple collections to one database?
I found a solution for that. Also the answer shows how to configure network so the webapp can see the mongodb container. Structure of files: Web.Application . +-- docker_compose.yml +-- mongo | +-- dump | +-- DatabaseDb | +-- Dockerfile | +-- restore.sh docker-compose.yml version: '3.4' services: webapp: container_name: webapp image: ${DOCKER_REGISTRY-}webapp build: context: ./Web.Application/ dockerfile: Dockerfile environment: - ASPNETCORE_ENVIRONMENT=Development depends_on: - mongo networks: clusternetwork: ipv4_address: 1.1.0.1 mongo: container_name: mongo build: context: ./Web.Application/mongo/ dockerfile: Dockerfile networks: clusternetwork: ipv4_address: 1.1.0.12 networks: clusternetwork: driver: bridge ipam: driver: default config: - subnet: 1.1.0.0/24 ./Web.Application/mongo/Dockerfile: FROM mongo AS start COPY . . COPY restore.sh /docker-entrypoint-initdb.d/ ./Web.Application/mongo/restore.sh: #!/bin/bash mongorestore --db DatabaseDb ./dump/DatabaseDb