{"id":15861903,"url":"https://github.com/owenrumney/local_k8s","last_synced_at":"2025-03-16T00:31:24.119Z","repository":{"id":49128688,"uuid":"378984466","full_name":"owenrumney/local_k8s","owner":"owenrumney","description":"Create a local K8s environment with ansible and ubuntu cloud img","archived":false,"fork":false,"pushed_at":"2022-07-29T09:03:15.000Z","size":30,"stargazers_count":4,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-27T04:26:02.303Z","etag":null,"topics":["ansible","kubernetes","learning"],"latest_commit_sha":null,"homepage":"","language":"Jinja","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/owenrumney.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":"2021-06-21T15:50:32.000Z","updated_at":"2024-10-03T05:15:36.000Z","dependencies_parsed_at":"2022-09-24T09:01:24.880Z","dependency_job_id":null,"html_url":"https://github.com/owenrumney/local_k8s","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/owenrumney%2Flocal_k8s","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/owenrumney%2Flocal_k8s/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/owenrumney%2Flocal_k8s/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/owenrumney%2Flocal_k8s/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/owenrumney","download_url":"https://codeload.github.com/owenrumney/local_k8s/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243801635,"owners_count":20350107,"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":["ansible","kubernetes","learning"],"created_at":"2024-10-05T22:21:06.611Z","updated_at":"2025-03-16T00:31:23.822Z","avatar_url":"https://github.com/owenrumney.png","language":"Jinja","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Notes\n\n## Assumptions\n\nThe following assumptions have been made\n\n- you have ansible installed\n- you have got sshd running and can ssh to the localhost\n\n## Local changes required\n\nThe following changes are required in the in `ansible/k8s/group_vars/all.yaml`\n\n- `private_key_path` - the path the the private portion of the ssh keypair\n\n## Bridge network\n\n\u003e I've used netplan for my  bridge, other approaches are available but you'll need to use their own instructions\n\nCreate a netplan bridge pointing to the physical interface, this will go into `/etc/netplan/01_kvm_bridge.yaml`\n\n```yaml\nnetwork:\n    version: 2\n    renderer: networkd\n    ethernets:\n        enp39s0:\n            dhcp4: false\n            dhcp6: false\n    bridges:\n        br0:\n            interfaces: [ enp39s0 ] # the interface on your machine\n            addresses: [ 192.168.0.100/24 ]\n            gateway4: 192.168.0.1\n            mtu: 1500\n            nameservers:\n                addresses: [ 8.8.8.8, 8.8.4.4 ]\n            parameters:\n                stp: true\n                forward-delay: 4\n            dhcp4: no\n            dhcp6: no\n```\n\nNow generate with `sudo netplan generate`\n\nNow apply with `sudo netplan apply`\n\n## Host IP Tables\n\nSome changes to host IP tables to route traffic from guest to internet correctly\n\n```bash\nsudo iptables -I FORWARD -i br0 -j ACCEPT\nsudo iptables -I FORWARD -o br0 -j ACCEPT\n```\n\n### Downloading the image\n\nRun `images/get_focal_image.sh` to download the ubuntu image locally. You'lll need this as the base image of the nodes.\n\n\n### Running from scratch\n\nMake sure that the vars in `ansible/k8s/group_vars/all.yaml` are correct, paying attention to paths and worker counts.\n\n```bash\ncd ansible/k8s\n\nexport ANSIBLE_PASSWORD=\u003cyourpassword\u003e\n\nansible-playbook -i inventories/hosts.ini install_from_scratch.yaml\n```\n\n### Kubectl\n\nAs part of the process, the kube config will be pulled back to your machine and put into the folder `~/.kube/virtconfig/\u003cmasterHostName\u003e/etc/kubernetes/admin.conf` to protect any existing config you have. To use the virt cluster, `export KUBECONFIG `\n\n```bash\nexport KUBECONFIG=~/.kube/virtconfig/192.168.0.150/etc/kubernetes/admin.conf\n```\n\nNow you can use `kubectl` to interact with the cluster\n\n### Accessing the master\n\nThe master node can be accessed using now with `ssh k8s@master-1`\n\n### Destroying the cluster\n\n```bash\nvirsh destroy master-1 \u0026\u0026 virsh undefine master-1\n\nfor i in {1-3}; do virsh destroy worker-$i \u0026\u0026 virsh undefine worker-$i; done\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fowenrumney%2Flocal_k8s","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fowenrumney%2Flocal_k8s","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fowenrumney%2Flocal_k8s/lists"}