Code Monkey home page Code Monkey logo

ansible-collection-k8s's Introduction

Kubernetes Collection for Ansible

Build Status

This collection contains Kubernetes-related roles and Ansible plugins and modules maintained by Jeff Geerling (geerlingguy).

It includes:

Usage

Install this collection locally:

ansible-galaxy collection install geerlingguy.k8s -p ./collections

Then you can use the roles from the collection in your playbooks:

---
- hosts: all

  collections:
    - geerlingguy.k8s

  roles:
    - kubernetes
    - helm
    - role: k8s_manifests
      vars:
        k8s_manifests_base_dir: ''
        k8s_manifests:
          - monitoring/prometheus
          - dir: docker-registry
            namespace: registry

If you want to be more explicit, you can use the fully-qualified role name when referring to a role in this collection, like geerlingguy.k8s.kubernetes instead of just kubernetes. This could be helpful if, for example, you maintain a separate kubernetes role in another place on your local workstation.

Development

Currently, all the Kubernetes roles (inside roles/) are Git submodules, and work on the roles themselves should take place in the upstream Role repository. At some point, the roles might move into this repository for their canonical home.

This collection has some integration tests (inside molecule/), however, which pull all the roles together and ensure they work in tandem on the latest supported platforms.

To run a particular test scenario, you need to install molecule and the OpenShift Python client (pip install molecule openshift), then you can run:

molecule test -s [scenario]

For example, to run the k8s_manifests role test scenario:

molecule test -s test-manifests

If you would like to develop the collection or leave a scenario running for debugging, use molecule converge to run the scenario but not tear down the local test environment.

Pushing a new version

Before tagging a new version, make sure all the git submodules are up to date:

git submodule update --recursive --remote

Then commit and push all changes, and make sure all tests are passing.

Then tag the new version of the collection and push the tag.

Once pushed, if tests pass, Travis CI will deploy the new collection version using the playbook in scripts/deploy.yml. That directory also contains the galaxy.yml template that will be used to build the collection metadata.

Author

This collection was created in 2019 by Jeff Geerling, author of Ansible for DevOps and Ansible for Kubernetes.

ansible-collection-k8s's People

Contributors

geerlingguy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ansible-collection-k8s's Issues

Build k8s_template module

See: ansible/ansible#60134

Basically build a module that makes it simpler to pass in a template (e.g. my-manifest.yml) which can have one or more YAML documents. Parse each document separately, template it via Jinja2, and then pass it to the K8s API as the normal k8s module does...

Add `k8s_wait` module

Just wanted to throw this out here, since it's something that would be convenient in a number of circumstances.

A common pattern for K8s deployments is:

  1. Apply a manifest to create a new Deployment.
  2. Wait for all the Pods in this Deployment to be Ready.
  3. Do other stuff.

Currently, for number 2, you can futz around with the returned data from k8s or k8s_info and use until/retries to get something working, or you can do a more simple method (if you have kubectl available) using kubectl wait:

kubectl wait --for=condition=Ready pods --selector app=my-app-name --timeout=60s

At a basic level, I'd want something like:

- name: Wait for my-app-name pods to be ready.
  k8s_wait:
    for: condition=Ready
    type: pods
    selector:
      - app=my-app-name
    timeout: 60s

Something along those lines... not sure. But it would be nice to be able to specify this in a more structured way, and not have to rely on kubectl being present for a task like:

- name: Wait for my-app-name pods to be ready.
  command: >
    kubectl wait --for=condition=Ready
    pods --selector app=my-app-name --timeout=60s
  changed_when: false

Where to give details of k8s master and worker node

Hi All,

I am new to ansible and trying to set up k8s cluster using this collection.
I have installed ansible and define master node and worker node details in /etc/ansible/hosts file.
I am not sure where to mention these node details if I use geerlingguy/ansible-collection-k8s collection.

I have gone through all yml files but no luck.

Please help me.

Add molecule tests for Travis CI

The basic idea:

  1. Have a playbook that runs the kubernetes role to set up kubernetes on a single node instance.
  2. Same playbook then runs k8s_manifests with a test deployment of something (e.g. prometheus or maybe even something simpler).

Packaged collection has git related files

roles/k8s_manifests/.git

Files like above should not be packaged in the collection, having that file breaks git status and other commands, and prevents ansible-test from working when that collection is installed.

Never fail, and after it only do if failed is conflicting!

Can you please help! I can't setup dashboard

- name: Check if Kubernetes Dashboard UI service already exists.
  shell: kubectl get services --namespace kube-system | grep -q kubernetes-dashboard
  changed_when: false
  **failed_when: false**
  register: kubernetes_dashboard_service
  when: kubernetes_enable_web_ui | bool

- name: Enable the Kubernetes Web Dashboard UI (if configured).
  command: "kubectl create -f {{ kubernetes_web_ui_manifest_file }}"
  when:
    - kubernetes_enable_web_ui | bool
    - **kubernetes_dashboard_service is failed**

The output if I run is the following

TASK [geerlingguy.kubernetes : Check if Kubernetes Dashboard UI service already exists.] **************************************************************************************************************************************************************************************
ok: [193.224.23.11]

TASK [geerlingguy.kubernetes : Enable the Kubernetes Web Dashboard UI (if configured).] ***************************************************************************************************************************************************************************************
skipping: [193.224.23.11]

If I run the command it fails, only the failed_when: false override it

$ ansible -i hosts -b -u debian k8s-1 -m shell -a "kubectl get services --namespace kube-system | grep -q kubernetes-dashboard"

193.224.23.11 | FAILED | rc=1 >>
non-zero return code

$ 

Any hint would be appreciated!
Thanks!

Add molecule test scenario for kubernetes role

I added a simple test scenario that verifies the k8s_manifests role in #1, now I'd like to add a scenario that verifies the kubernetes role.

I could use the ubuntu1804 or debian10 ansible base image and then run the role inside with defaults.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.