Kubernetes module #1139
Comments
Hi folks - looking for some input from you on preferred implementation approach to this module. Grab a cup of coffee, this will be lengthy... For the sake of discussion, let's use Namespaces. Please take a moment to look at the Option 1: Hand-codingOne option is to hand-code API coverage in a set of Ansible modules, likely one for each resource (pods, replica-controllers, services, namespaces, etc). This would allow ansible users to write playbooks that would may contain something like, - name: Kubernetes finance group apps
vars:
api_endpoint: 123.45.67.89
api_password: redacted
tasks:
- name: Create the development namespace for finance group
kubernetes_namespace:
name: finance-dev
labels:
- development
- finance While this may be a good approach for users to map the kubernetes world into the ansible world, I'm concerned that it will be hard to cover the full kubernetes API sufficiently. It would also lead to a tremendous amount of code to write and maintain. Additionally, if a user already has existing kubernetes JSON files, they need to re-write them into the ansible YAML format. Option 2: Playbooks utilize existing kubernetes JSON filesA second option would be for the ansible modules to just pass pure kubernetes JSON files to the kubernetes API and return the results. To illustrate this approach, let's assume we already have the kubernetes JSON file, {
"kind": "Namespace",
"apiVersion": "v1",
"metadata": {
"name": "development",
"labels": {
"name": "development"
}
}
} The corresponding ansible YAML for this could look something like, - name: Kubernetes finance group apps
vars:
api_endpoint: 123.45.67.89
api_password: redacted
tasks:
- name: Create the development namespace for finance group
kubernetes:
kubernetes_file: /path/to/namespace-dev.json
state: present Now, the module merely reads the contents of the file, creates the If the user wants to delete this namespace, for convenience, they should be able to reference the same file. The module will have need to be able to map a To handle idempotency, the module will need to know that My preference: Option 2I'm leaning much more toward Option 2, but would like other's input before doing more tangible work. As I see it, the benefits are:
Thoughts? |
My main concern with option #2 is that it removes the ability to specify variables for values in the JSON file. I know or cloudformations module can accept a list of template parameters, but this is more a built-in function of cloudformations rather than our module code. Reading the docs, I'm not seeing a comparable option, unless I missed it? |
Option 1 it is. Shortly after posting this, I realized that we'd sacrifice variables with Option 2 and I can't find an elegant way of dealing with that. The |
@erjohnso yeah, the only other option I see is to support both ways. Not sure how painful that'd be, but since simply specifying an existing JSON file is pretty painless and easy it might not be too much more work. Thoughts? |
We actually prefer YAML to JSON in our examples. JSON is for machines, YAML is for humans is our general rule of thumb. |
a note that says 'since JSON is a subset of YAML, you can also use it if you must' |
Ok, I think I'm on a good path and thanks everyone for the input. I have a working stub for creating Namespaces and it maps very cleanly to the v1.Namespace definition, so the end user won't have to do a lot of extra conversion. For reference, here's an example of the Kubernetes v1.Namespace definition in YAML: kind: Namespace
apiVersion: v1
metadata:
name: my-namespace
labels:
env: production
version: stable
annotations:
key1: value1
key2: value2
spec:
finalizers: [] Here's what it looks like in an ansible playbook: ---
# Create a k8s app
- hosts: localhost
vars:
api_endpoint: 123.45.67.89
url_username: admin
url_password: redacted
tasks:
- name: Create a new k8s namespace
kubernetes_namespace:
api_endpoint: "{{ api_endpoint }}"
url_username: "{{ url_username }}"
url_password: "{{ url_password }}"
metadata:
name: my-namespace
labels:
env: production
version: stable
annotations:
a1: value1
a2: value2
state: present I'm essentially handing back the JSON response as-is, and the snippet of output from
Everyone cool with this? I'm happy with it. 🍶 |
For anyone following along, here's what I have so far[1]. It's a bit different than what was last proposed, but I think overall, this is much cleaner. It supports in-line YAML and users can effectively copy/paste the Kubernetes YAML examples into their playbooks. With this approach, they can modify the in-line YAML to allow for ansible's variable substitution. It also supports re-using the YAML files on disk and the user's playbooks can just point to existing Kubernetes YAML files. But this comes at the cost of not allowing variable substitution. Lastly, I've started stubbing out some fake TODO:
[1] https://github.com/erjohnso/ansible-modules-extras/blob/google-kubernetes/clustering/kubernetes.py |
Closing this issue out now that there is a PR for the module: #1229 |
Sadly I just found this. I would have suggestted option #2 but make the json/yaml a jinja template file instead of a static file... Ok, off to see the actual code. |
Google is going to contribute an ansible module for managing a kubernetes cluster. This module will assume the cluster exists and will require the user to specify endpoint / authorization info and will perform basic CRUD operations against the Kubernetes v1 API[1].
I suspect the best place for this module to live is under
clustering/
. Please voice objections if an alternate location is preferred.[1] https://raw.githubusercontent.com/kubernetes/kubernetes/master/api/swagger-spec/v1.json
/cc @gregdek, @jimi-c, @bcoca
The text was updated successfully, but these errors were encountered: