{"id":24623076,"url":"https://github.com/cdent/placedock","last_synced_at":"2025-03-19T01:14:45.724Z","repository":{"id":44573091,"uuid":"112041079","full_name":"cdent/placedock","owner":"cdent","description":"Messing around with openstack placement in docker and kubernetes, probably not for real use.","archived":false,"fork":false,"pushed_at":"2022-02-07T15:08:04.000Z","size":73,"stargazers_count":1,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-01T03:29:00.285Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Dockerfile","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cdent.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-25T23:13:53.000Z","updated_at":"2022-02-07T15:08:08.000Z","dependencies_parsed_at":"2022-08-31T15:51:58.026Z","dependency_job_id":null,"html_url":"https://github.com/cdent/placedock","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdent%2Fplacedock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdent%2Fplacedock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdent%2Fplacedock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdent%2Fplacedock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cdent","download_url":"https://codeload.github.com/cdent/placedock/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244333022,"owners_count":20436123,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-25T03:14:08.429Z","updated_at":"2025-03-19T01:14:45.708Z","avatar_url":"https://github.com/cdent.png","language":"Dockerfile","funding_links":[],"categories":[],"sub_categories":[],"readme":"\nThis repo provides a collection of tools for creating and running\nthe [OpenStack](https://openstack.org/)\n[Placement](https://developer.openstack.org/api-ref/placement/)\nservice in one or more containers for experimental purposes. The\ntools are set up to allow a variety of different usage scenarios\nincluding:\n\n* Running the container with docker to sit beside a running\n  OpenStack installation, such as devstack, talking to an\n  established remote database.\n* Using a single sqlite3 database within the container to do\n  _placement-only_ testing (to do things like model nested resource\n  providers and complex queries thereof).\n* Running in whatever fashion, but doing the work at startup to make\n  sure that the target database has the proper tables.\n* Running in kubernetes with a horizontal pod autoscaler, via a\n  helm-chart (included here).\n\n**Warning:** At this time the `Dockerfile` builds from master. This\nconfiguration is not regularly tested for production use, but is\npretty standard. If you want to give it a go and it works for you,\ngreat, please let me know.\n\nThe work that created this is documented in a series of blog\nposts called \"Placement Container Playground\", parts\n[1](https://anticdent.org/placement-container-playground.html),\n[2](https://anticdent.org/placement-container-playground-2.html),\n[3](https://anticdent.org/placement-container-playground-3.html),\n[4](https://anticdent.org/placement-container-playground-4.html),\n[5](https://anticdent.org/placement-container-playground-5.html),\n[6](https://anticdent.org/placement-container-playground-6.html),\n[7](https://anticdent.org/placement-container-playground-7.html),\nand\n[8](https://anticdent.org/placement-container-playground-8.html),\n\nIf you take issue with anything here or have some suggestions or\nhave anything to say, please create an [issue](/cdent/placement/issues).\n\n# The Basics\n\nThe core pieces of this puzzle are:\n\n* `Dockerfile`: descrbing how the container is built.\n* `placement-requirements.txt`: A pip requirements file that\n  describes which Python modules to install when building the\n  container.\n* `shared/placement-uwsgi.ini`: a generic configuration for running\n  the placement service under\n  [uwsgi](https://uwsgi-docs.readthedocs.io/) using the `http`\n  protocol, exposed over port 80. Copied into the container.\n* `shared/startup.sh`: A script that runs when the container starts to\n  manage some configuration defaults, optionally sync the database,\n  and start the uwsgi server. Copied into the container.\n\nWith a checkout out of the repo it is possible to do just this to get a\ncontainer running it's own database (depending on your environment you\nmay need sudo):\n\n```\ndocker build -t placedock .\ndocker run -t -p 127.0.0.1:8081:80 \\\n    -e \"OS_PLACEMENT_DATABASE__SYNC_ON_STARTUP=True\" \\\n    -e \"OS_API__AUTH_STRATEGY=noauth2\" \\\n    placedock\ncurl http://localhost:8081/ | json_pp\n```\n\nResults in:\n\n```json\n{\n   \"versions\" : [\n      {\n         \"min_version\" : \"1.0\",\n         \"id\" : \"v1.0\",\n         \"status\" : \"CURRENT\",\n         \"max_version\" : \"1.30\",\n         \"links\" : [\n            {\n               \"href\" : \"\",\n               \"rel\" : \"self\"\n            }\n         ]\n      }\n   ]\n}\n```\n\nThis is a container running placement using its own sqlite\ndatabase. When the container is terminated, the data goes.\n\n# The Environment\n\nThere are several environment variables that can be used when\nrunning the container (either via `-e` or `--env-file` on a `docker\nrun` or however you happen to be establishing a pod in kubernetes.\nSome of the variables are specific to this methods, the rest (those\nstarting with `OS_`) correspond to the placement configuration\nsettings, all of which may be managed from the environment (removing\nthe need for a config file).\n\n* `OS_PLACEMENT_DATABASE__CONNECTION`: Database connection string.\n  Defaults to `sqlite:////cats.db`, a database local to the container.\n* `OS_PLACEMENT_DATABASE__SYNC_ON_STARTUP`: If `True` then do database\n   migrations. Defaults to `False.\n* `OS_API__AUTH_STRATEGY`: Either `keystone` or `noauth2`. No default, if\n  this is not set, the container will fail to start.\n\nIf the `OS_API__AUTH_STRATEGY` is `noauth2`, HTTP requests to placement must\ninclude a header named `x-auth-token` with a value of `admin` in order to be\nauthentic.\n\nIf the `OS_API__AUTH_STRATEGY` is `keystone`, additional configuration\nis needed so middleware knows how to talk to a keystone service. This\ndescription uses the `password` auth type. If you are using something\ndifferent the options will be different.\n\n* `OS_KEYSTONE_AUTHTOKEN__USERNAME`: The username\n* `OS_KEYSTONE_AUTHTOKEN__PASSWORD`: and password for talking to keystone.\n* `OS_KEYSTONE_AUTHTOKEN__WWW_AUTHENTICATE_URI`: The URL where keystone is,\n  used in the `www-authenticate` header.\n* `OS_KEYSTONE_AUTHTOKEN__MEMCACHED_SERVERS`: A `host:port` combo, or a\n  comma-separated list thereof, of memcached servers. This is required or\n  otherwise the keystone middleware really drags.\n* `OS_KEYSTONE_AUTHTOKEN__AUTH_TYPE`: Set to `password` to use usernames and\n  password with keystone.\n* `OS_KEYSTONE_AUTHTOKEN__AUTH_URL`: The URL placement verifies tokens with,\n  often the same as `www_authenticate_uri`.\n* `OS_KEYSTONE_AUTHTOKEN__PROJECT_DOMAIN_NAME`\n* `OS_KEYSTONE_AUTHTOKEN__PROJECT_NAME`\n* `OS_KEYSTONE_AUTHTOKEN__USER_DOMAIN_NAME`\n* `OS_KEYSTONE_AUTHTOKEN__USERNAME`\n* `OS_KEYSTONE_AUTHTOKEN__PASSWORD`\n\nWhen using keystone, HTTP requests to placement must include a header named\n`x-auth-token` with a value of a valid keystone token that has the `admin`\nrole.\n\n# Devstack\n\nIf you want to use this setup with devstack, build a devstack (with\nnova and placement enabled, they are by default) and gather some\ninformation from the built stack:\n\n* Use the value of `[placement_database]/connection` in\n  `/etc/placement/placement.conf` as `OS_PLACEMENT_DATABASE__CONNECTION`.\n  You will probably need to change the IP address.\n* Use the value of `ADMIN_PASSWORD` in `local.conf` as\n  `OS_KEYSTONE_AUTHTOKEN__PASSWORD`.\n* Use `placement` for `OS_KEYSTONE_AUTHTOKEN__USER`.\n* The value for `OS_KEYSTONE_AUTHTOKEN__WWW_AUTHENTICATE_URI` is printed\n  when `stack.sh` completes:\n  \"Keystone is serving at http://192.168.1.76/identity/\"\n* The value for `OS_KEYSTONE_AUTHTOKEN__MEMCACHED_SERVERS` and the several\n  other settings can be extracted from the `[keystone_authtoken]` section of\n  `/etc/placement/placement.conf`.\n\nYou can put these in a `--env-file` that might look like this:\n\n```\nOS_DEFAULT__DEBUG=True\nOS_PLACEMENT_DATABASE__CONNECTION=mysql+pymysql://root:secret@192.168.1.76/placement?charset=utf8\nOS_API__AUTH_STRATEGY=keystone\nOS_KEYSTONE_AUTHTOKEN__WWW_AUTHENTICATE_URI=http://192.168.1.76/identity\nOS_KEYSTONE_AUTHTOKEN__MEMCACHED_SERVERS=localhost:11211\nOS_KEYSTONE_AUTHTOKEN__PROJECT_DOMAIN_NAME=Default\nOS_KEYSTONE_AUTHTOKEN__PROJECT_NAME=service\nOS_KEYSTONE_AUTHTOKEN__USER_DOMAIN_NAME=Default\nOS_KEYSTONE_AUTHTOKEN__PASSWORD=secret\nOS_KEYSTONE_AUTHTOKEN__USERNAME=placement\nOS_KEYSTONE_AUTHTOKEN__AUTH_URL=http://192.168.1.76/identity\nOS_KEYSTONE_AUTHTOKEN__AUTH_TYPE=password\n```\n\nClearly a lot of this could be automated, but I haven't got there\nyet.\n\nThen change `/etc/apache2/sites-enabled/placement-api.conf` to\nsomething like this:\n\n```\n\u003cProxy balancer://placement\u003e\n    # This placement is important\n    BalancerMember http://127.0.0.1:8080/placement\n\u003c/Proxy\u003e\n  \nProxyPass \"/placement\" balancer://placement\n```\n\nBuild and run your container:\n\n```\ndocker build -t placedock .\ndocker run -t -p 127.0.0.1:8080:80 \\\n    --env-file dockerenv placedock\n```\n\nAnd reload apache2 so it can get the new config.\n\nClues above should indicate how to have more containers to load\nbalance against. (Left as an exercise for the reader.)\n\n# Kubernetes\n\nYou can also run placement in Kubernetes. A helm chart is included\nin this repository that will do everything for you. You first need\na working kubernetes cluster and to [install\nhelm](https://docs.helm.sh/using_helm/#quickstart).\n\nOnce that is done, inspect `placement-chart/values.yaml` to\nunderstand the options. Using the defaults given there a single\nreplica of the the placement service will be created, using an\ninternal-to-container database, and the noauth2 strategy. This is\nuseful to see it working.\n\nChanging `replicaCount` to 0 will install a [Horizontal Pod\nAutoscaler](https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/)\ninto the cluster. This will not work unless a [metrics\nserver](https://github.com/kubernetes-incubator/metrics-server/tree/master/deploy)\nis installed in the cluster. On docker for mac a\n[workaround](https://stackoverflow.com/a/54106726) is required.\n\nSetting `ingress.enabled` to `true` will add placement to an ingress\nservice if one exists. If you need one [see the\ninstructions](https://kubernetes.github.io/ingress-nginx/deploy/).\n\nTo deploy the chart using the defaults do something like (feel free\nto choose a name you like):\n\n```\nhelm install ./placement-chart --name=placement\n```\n\nIf you want to install with the auto scaler and the ingress server\nturned on you can either edit values.yaml or set values from the\ncommand line:\n\n```\nhelm install --set ingress.enabled=true \\\n             --set replicaCount=0 \\\n             ./placement-chart\n```\n\nThe ingress server will be set up to dispatch based on an http host\nof `placement.local`. If you add an entry to `/etc/hosts` with that\nname and the ingress IP, you'll be able to reach placement with\nqueries like:\n\n```\ncurl -H 'x-auth-token: admin' http://placement.local/resource_providers\n```\n\nYou can also do a quick test using\n[gabbi](https://pypi.org/p/gabbi):\n\n```\ngabbi-run http://placement.local -- gabbi.yaml\n```\n\nTo exercise the auto scaler, it is important to understand the\n`resources` section of `values.yaml` and the `spec` section of\n`autoscaler.yaml`. As written they say:\n\n* start with one replica that is allowed to use 1/4 of a CPU\n* if utilization goes over 50% (that is 1/8th of a CPU) consider\n  creating another replica, up to 10.\n\nThese numbers were chosen because they allow me to see the\nautoscaling in action without requiring too much work.\n\n[Placement Container Playground\n5](https://anticdent.org/placement-container-playground-5.html)\ndescribes using `watch kubectl get hpa` to see resources and\nreplicas change and `ab` to cause some load. Since then a tool\ncalled [placeload](https://pypi.org/p/placeload) has been created\nwhich can also exercise a placement service.\n\nWhen you are done experimenting, helm allows you to clear away\nthe placement service:\n\n```\nhelm ls  # list the installed charts to get the name\nhelm delete --purge \u003cthe name\u003e\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcdent%2Fplacedock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcdent%2Fplacedock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcdent%2Fplacedock/lists"}