Skip to content

Commit

Permalink
helloworld sample update (istio#45355)
Browse files Browse the repository at this point in the history
* update helloworld to use gunicorn; bind TCP6 by default but offer a fallback option if necessary; introduce dual stack manifest for helloworld on k8s

Signed-off-by: ilrudie <ian.rudie@solo.io>

* python lint fix

Signed-off-by: ilrudie <ian.rudie@solo.io>

* Adding curl to the image, the old image had it and was used by some folks as a client as a result

Signed-off-by: ilrudie <ian.rudie@solo.io>

* fixing Dockerfile lint issues

Signed-off-by: ilrudie <ian.rudie@solo.io>

---------

Signed-off-by: ilrudie <ian.rudie@solo.io>
  • Loading branch information
ilrudie authored Jun 15, 2023
1 parent 1f91b25 commit ae5a7e3
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 2 deletions.
75 changes: 75 additions & 0 deletions samples/helloworld/helloworld-dual-stack.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
apiVersion: v1
kind: Service
metadata:
name: helloworld
labels:
app: helloworld
service: helloworld
spec:
ipFamilyPolicy: RequireDualStack
ipFamilies:
- IPv6
- IPv4
ports:
- port: 5000
name: http
selector:
app: helloworld
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: helloworld-v1
labels:
app: helloworld
version: v1
spec:
replicas: 1
selector:
matchLabels:
app: helloworld
version: v1
template:
metadata:
labels:
app: helloworld
version: v1
spec:
containers:
- name: helloworld
image: docker.io/istio/examples-helloworld-v1
resources:
requests:
cpu: "100m"
imagePullPolicy: IfNotPresent #Always
ports:
- containerPort: 5000
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: helloworld-v2
labels:
app: helloworld
version: v2
spec:
replicas: 1
selector:
matchLabels:
app: helloworld
version: v2
template:
metadata:
labels:
app: helloworld
version: v2
spec:
containers:
- name: helloworld
image: docker.io/istio/examples-helloworld-v2
resources:
requests:
cpu: "100m"
imagePullPolicy: IfNotPresent #Always
ports:
- containerPort: 5000
9 changes: 8 additions & 1 deletion samples/helloworld/src/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,16 @@ COPY requirements.txt ./
# install the dependencies and packages in the requirements file
RUN pip install --no-cache-dir -r requirements.txt

# old image had curl and could be used as a sample client if desired
RUN apt-get update \
&& apt-get install curl --no-install-recommends -y \
&& rm -rf /var/lib/apt/lists/*

EXPOSE 5000

ARG service_version
ENV SERVICE_VERSION ${service_version:-v1}

CMD ["python", "app.py"]
# image will bind on TCP6 by default. In k8s pod spec (in a deployment pod template most likely) override for explicit IPv4 if needed with the command shown below:
# ["gunicorn", "-b", "[0.0.0.0]:5000", "app:app", "-k", "gevent"]
CMD ["gunicorn", "-b", "[::]:5000", "app:app", "-k", "gevent"]
2 changes: 1 addition & 1 deletion samples/helloworld/src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ def health():


if __name__ == "__main__":
app.run(host='::', threaded=True)
app.run(host='127.0.0.1', threaded=True) # listen on IPv4; gunicorn will accept IPv6 from outside the pod
1 change: 1 addition & 0 deletions samples/helloworld/src/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ flask_bootstrap
json2html
simplejson
gevent
gunicorn

0 comments on commit ae5a7e3

Please sign in to comment.