June 2020
Intermediate to advanced
410 pages
9h 52m
English
So far, we have seen how to create namespaces from Ansible, so now, let's put a Service in the namespace we just created. Let's create a new playbook called k8s-svc.yaml with the following content:
---- hosts: localhost tasks: - name: Ensure the Service mysvc is present k8s: state: present definition: apiVersion: v1 kind: Service metadata: name: mysvc namespace: myns spec: selector: app: myapp service: mysvc ports: - protocol: TCP targetPort: 800 name: port-80-tcp port: 80
Before running it, we can execute kubectl get svc to ensure that the namespace has no Services. Make sure you're in the right namespace before running it! In my case, the output is as follows:
$ kubectl get svcNo resources found ...