Closed DazWilkin closed 6 years ago
Yes, you need to change at least packager_repo
and package_name
in examples/simple/example.py
.
Should we document it?
Thank you.
You solved my problem but that wasn't my question :-)
I was referring to this documentation which contradicts the examples/simple/example.py
https://metaparticle.io/tutorials/python/
from metaparticle import containerize
...
@containerize(
'docker.io/your-docker-user-goes-here',
options={
'ports': [8080],
'name': 'my-image',
'publish': True
})
def main():
Handler = MyHandler
httpd = SocketServer.TCPServer(("", port), Handler)
httpd.serve_forever()
So the documentation needs to be corrected to reflect the correct module name etc.
OK... Making progress...
Mashed-up the sample from the metaparticle.io Python page with this sample:
from metaparticle_pkg import Containerize
from six.moves import SimpleHTTPServer, socketserver
import socket
repo = 'docker.io/[[MY-DOCKER]]'
name = 'mp-python'
OK = 200
port = 8080
class MyHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self):
self.send_response(OK)
self.send_header("Content-type", "text/plain")
self.end_headers()
self.wfile.write("Hello Metaparticle [{}] @ {}\n".format(
self.path,
socket.gethostname()).encode('UTF-8')
)
print("request for {}".format(self.path))
def do_HEAD(self):
self.send_response(OK)
self.send_header("Content-type", "text/plain")
self.end_headers()
@Containerize(
package={
'name': name,
'repository': repo,
'publish': True,
},
runtime={
'ports': [
port
],
}
)
def main():
Handler = MyHandler
httpd = socketserver.TCPServer(("", port), Handler)
httpd.serve_forever()
if __name__ == '__main__':
print("Starting...")
main()
Runs under Docker locally:
curl http://localhost:8080/test
Hello Henry [/test] @ 8b31882c087c
I reviewed the code to work out -- I think !? -- the config for Kubernetes:
'replicas': 4,
'executor': 'metaparticle',
and this yields
Starting...
==> Detected container mp-python-c5b8b68d7-6kfvr:mp-python-0
==> Detected container mp-python-c5b8b68d7-t7ldn:mp-python-0
==> Detected container mp-python-c5b8b68d7-tqz82:mp-python-0
==> Detected container mp-python-c5b8b68d7-xvpph:mp-python-0
and:
kubectl get pods
NAME READY STATUS RESTARTS AGE
mp-python-c5b8b68d7-gxj65 1/1 Running 0 11s
mp-python-c5b8b68d7-p5lbd 1/1 Running 0 11s
mp-python-c5b8b68d7-stvqh 1/1 Running 0 11s
mp-python-c5b8b68d7-wkwpz 1/1 Running 0 11s
kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.63.240.1 <none> 443/TCP 1h
mp-python ClusterIP 10.63.240.159 <none> 8080/TCP 16s
The service is a ClusterIP and would be better (can I configure?) as a LoadBalancer, so:
kubectl run curl --image=radial/busyboxplus:curl -i --tty --rm
If you don't see a command prompt, try pressing enter.
[ root@curl-6896d87888-hqr6b:/ ]$ curl mp-python:8080/test
Hello Henry [/test] @ mp-python-c5b8b68d7-wkwpz
you need to set 'public': True
in your runtime config to get an external IP address...
(at least that should work in Python, if it doesn't file another bug...)
oops, didn't mean to close this...
I was wrong, I think it was meant to be 'publicAddress': True
But as I mentioned in the bug, I should probably switch that to public
Apologies for my delay in replying.
That did not work. 'publicAddress': True
is accepted but I continue to receive a Cluster IP:
kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.43.240.1 <none> 443/TCP 49m
mp-python ClusterIP 10.43.255.186 <none> 8080/TCP 2m
I did not upgrade my code.
I'll try to repro this tonight...
From: Daz Wilkin notifications@github.com Sent: Thursday, February 22, 2018 2:39 PM To: metaparticle-io/package Cc: Brendan Burns; State change Subject: Re: [metaparticle-io/package] Python sample does not work as documented (#82)
Apologies for my delay in replying.
That did not work. 'publicAddress': True is accepted but I continue to receive a Cluster IP:
kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.43.240.1
I did not upgrade my code.
— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHubhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fmetaparticle-io%2Fpackage%2Fissues%2F82%23issuecomment-367847446&data=04%7C01%7Cbburns%40microsoft.com%7Ca73304cb1b8344a6191b08d57a45321a%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636549360064889088%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwifQ%3D%3D%7C-1&sdata=DzMjBBA%2FokrhTtzdyLG%2BzkGDknZC7k9krm%2FjeEp99gk%3D&reserved=0, or mute the threadhttps://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAFfDgiHdhIkn2HsD7aeljtTbwQiKaouIks5tXey6gaJpZM4RqrDs&data=04%7C01%7Cbburns%40microsoft.com%7Ca73304cb1b8344a6191b08d57a45321a%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636549360064889088%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwifQ%3D%3D%7C-1&sdata=WhcIu%2BxpwwLLEzo7R%2Bymmv7YAfOR%2BJwYo5unz4YQKHI%3D&reserved=0.
This is mostly my personal curiosity and no customer is being harmed by this not working as intended. Very much value your help @brendanburns and I'm inspired by metaparticle but, unless others are pestering, please don't prioritize this.
I'm headed out on vacation tomorrow and will be non-responsive for a week.
I did not update metaparticle nor refresh the repo.
I added the property as you suggested.
The code is as-above and:
@Containerize(
package={
'name': name,
'repository': repo,
'publish': True,
},
runtime={
'ports': [
port
],
'replicas': 4,
'executor': 'metaparticle',
'publicAddress': True,
}
)
pip freeze
backports.ssl-match-hostname==3.5.0.1
certifi==2018.1.18
chardet==3.0.4
docker==2.7.0
docker-pycreds==0.2.1
idna==2.6
ipaddress==1.0.19
metaparticle-pkg==0.6.3
requests==2.18.4
six==1.10.0
urllib3==1.22
websocket-client==0.46.0
What else can I provide that would help you repo?
Does mp-compiler
report its version?
Ok, I fixed this in #98
The syntax is now:
runtime={'ports': [8080], 'executor': 'metaparticle', 'replicas': 3, 'public': True}
And you need to update to metaparticle_pkg
version 0.6.6
I followed the instructions (honest):
I tried the Python sample as-is:
This returns:
I then tried:
This returns:
I briefly explored the package but it's not immediately obvious to me what needs to be done :-(