GithubHelp home page GithubHelp logo

zimmertr / tjs-kubernetes-service Goto Github PK

View Code? Open in Web Editor NEW
526.0 35.0 82.0 4.98 MB

Enable enthusiasts and administrators alike to easily provision highly available and production-ready Kubernetes clusters on Proxmox VE.

License: GNU General Public License v3.0

Shell 6.78% HCL 93.22%
kubernetes proxmox terraform linux docker qemu virtualization containerization cluster-api-provider-proxmox proxmox-ve

tjs-kubernetes-service's Introduction

TJ's Kubernetes Service


Summary

TJ's Kubernetes Service, or TKS, is an IaC project that is used to deliver Kubernetes to Proxmox. Across the years, it has evolved many times and has used a multitude of different technologies. Nowadays, it is a relatively simple collection of Terraform manifests thanks to the work of BPG and Sidero Labs.


Requirements

Requirement Description
terraform Used for creating the cluster
kubectl Used for upgrading the Talos nodes to install QEMU Guest Agent and removing nodes from the cluster
talosctl Used for upgrading the Talos nodes to install QEMU Guest Agent and removing nodes from the cluster
ssh-agent Used for connecting to the Proxmox server to bootstrap the Talos image
Proxmox You already know
DNS Resolver Used for configuring DHCP reservation during cluster creation and DNS resolution within the cluster

Instructions

  1. Configure SSH access with a private key to your Proxmox server. This is needed to provision the installation image and also for certain API actions executed by the Terraform provider.

  2. Create an API token on Proxmox. I use my create_user Ansible role to create mine.

  3. Add your SSH key to ssh-agent:

    eval "$(ssh-agent -s)"
    ssh-add --apple-use-keychain ~/.ssh/sol.Milkyway
  4. Set the environment variables required to authenticate to your Proxmox server according to the provider docs. I personally use an API Token and define them in vars/config.env. Source them into your shell.

    source vars/config.env
  5. Review variables.tf and set any overrides according to your environment in a new tfvars file.

  6. Create DNS records and DHCP reservations for your nodes according to your configured Hostname, MAC address, and IP Address prefixes. Here is how mine is configured for two clusters:

    Hostname MAC Address IP Address
    k8s-vip N/A 192.168.40.10
    k8s-cp-1 00:00:00:00:00:11 192.168.40.11
    k8s-cp-2 00:00:00:00:00:12 192.168.40.12
    k8s-cp-3 00:00:00:00:00:13 192.168.40.13
    k8s-node-1 00:00:00:00:00:21 192.168.40.21
    k8s-node-2 00:00:00:00:00:22 192.168.40.22
    k8s-node-3 00:00:00:00:00:23 192.168.40.23
    test-k8s-vip N/A 192.168.40.50
    test-k8s-cp-1 00:00:00:00:00:51 192.168.40.51
    test-k8s-cp-2 00:00:00:00:00:52 192.168.40.52
    test-k8s-cp-3 00:00:00:00:00:53 192.168.40.53
    test-k8s-node-1 00:00:00:00:00:61 192.168.40.61
    test-k8s-node-2 00:00:00:00:00:62 192.168.40.62
    test-k8s-node-3 00:00:00:00:00:63 192.168.40.63
  7. Initialize Terraform and create a workspace for your Terraform state. Or configure a different backend accordingly.

    terraform init
    terraform workspace new test
  8. Create the cluster

    terraform apply --var-file="vars/test.tfvars"
  9. Retrieve the Kubernetes and Talos configuration files. Be sure not to overwrite any existing configs you wish to preserve. I use kubecm to add/merge configs and kubectx to change contexts.

    mkdir -p ~/.{kube,talos}
    touch ~/.kube/config
    
    terraform output -raw talosconfig > ~/.talos/config-test
    terraform output -raw kubeconfig > ~/.kube/config-test
    
    kubecm add -f ~/.kube/config-test
    kubectx admin@test
  10. Confirm Kubernetes is bootstrapped and that all of the nodes have joined the cluster. The Controlplane nodes might take a moment to respond. You can confirm the status of each Talos node using talosctl or by reviewing the VM consoles in Proxmox.

    watch kubectl get nodes,all -A

Post Install

Installing QEMU Guest Agent

Talos installs the QEMU Guest Agent, but it won't be enabled until the nodes are upgraded. Once everything in the cluster has become Ready, upgrade the nodes using talosctl or the manage_nodes script. If you opted to disable Flannel, you need to install a CNI before this will work.

NODES=$(kubectl get nodes --no-headers=true | awk '{print $1}' | tr '\n' ',')
./bin/manage_nodes upgrade $NODES

Installing A Different CNI

By default, Talos uses Flannel. To use a different CNI make sure that var.talos_disable_flannel is set to true during provisioning. The cluster will not be functional and you will not be able to upgrade the nodes to install QEMU Guest Agent until a CNI is enabled. Cilium can be installed using my project found here. You will also likely want to install Kubelet CSR Approver to automatically. accept the required certificate signing requests. Alternatively, after installing you can accept them manually:

kubectl get csr
kubectl certificate approve $CSR

Scaling the Cluster

The Terraform provider makes it quite easy to scale in, out, up, or down. Simply adjust the variables for resources or desired number of nodes and run terraform plan again. If the plan looks good, apply it.

In the event you scale down a node, terraform will execute a local-provisioner that runs manage_nodes to remove the node from the cluster for you as well:

./bin/manage_nodes remove $NODE

Considerations:

  • As QEMU Guest Agent's installation is not managed by Terraform, be sure to run ./bin/manage_nodes upgrade $NODE against any new nodes that are added to enable it. Otherwise, Terraform will have issues interacting with it through the Proxmox API.
  • At this time I don't think it's possible to choose a specific node to remove. You must scale up and down the last node.
  • Due to the way I configure IP Addressing using DHCP reservations, there is a limit of both 9 controlplanes and 9 workernodes.

Installing Other Apps

You can find my personal collection of manifests here.


Troubleshooting

Terraform is Stuck Deleting

Proxmox won't be able to issue a shutdown signal to the virtual machines unless QEMU Guest Agent is enabled. This can lead to Terraform trying to destroy nodes unsuccessfully until the API times out the command. In the event this occurs, you can work connect to Proxmox manually and remove the VMs, then proceed with terraform destroy as usual. For example:

ssh -i ~/.ssh/sol.milkyway [email protected] "rm /var/lock/qemu-server/lock-*; qm list | grep 40 | awk '{print \$1}' | xargs -L1 qm stop && sleep 5 && qm list | grep 40 | awk '{print \$1}' | xargs -L1 qm destroy"

tjs-kubernetes-service's People

Contributors

jgoodhcg avatar nicholasrobertm avatar renovate[bot] avatar romracer avatar zimmertr 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  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  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

tjs-kubernetes-service's Issues

Unable to deploy heapster and influxdb

This is a fresh deployment as of last night. I am unable to deploy heapster and influxdb. Running the following versions-

Running pve-manager/6.0-4/2a719255 (running kernel: 5.0.15-1-pve)

https://cdimage.debian.org/cdimage/openstack/current/debian-10.1.2-20190925-openstack-amd64.qcow2

TASK [Deploying Heapster, InfluxDB, and configuring RBAC for the Dashboard stack.] ********************************************************** ok: [mymaster] => (item=sa_heapster.yml) ok: [mymaster] => (item=rb_heapster.yml) ok: [mymaster] => (item=svc_heapster.yml) ok: [mymaster] => (item=svc_influxdb.yml) failed: [mymaster] (item=dep_heapster.yml) => {"ansible_loop_var": "item", "changed": false, "item": "dep_heapster.yml", "msg": "Failed to find exact match for extensions/v1beta1.Deployment by [kind, name, singularName, shortNames]"} failed: [mymaster] (item=dep_influxdb.yml) => {"ansible_loop_var": "item", "changed": false, "item": "dep_influxdb.yml", "msg": "Failed to find exact match for extensions/v1beta1.Deployment by [kind, name, singularName, shortNames]"}

tls: internal error on the cluster and see you refer to a potential solution?

Talos 1.5.3, k8s 1.28.2

TLS Issue

Hi and thanks for sharing your setup :)

New to talos and k8s (been using k3s) and have an issue with internal certs not getting signed.

All the csr are 'denied' and I am unable to get the metrics server working amongst other things.

You refer in the link to that thread being the solution, but I am not so sure how that relates here?

Any pointers would be a great help to get the cluster core up and running :)

Thanks

No inter-pod communication in Buster

Man, I found this project looking for a way to run k8s on Proxmox easily. I thought "hell yea! this guy did the work for me."

But then I tried it and failed despite not being new to any of this. My pods were unable to communicate with each other. I tried everything I could think of: using canal instead of calico, using flannel instead of canal, using vxlan, using udp, using host-gw. Nothing was working. I could maybe ping between nodes, but certainly not pods.

Then, I found it! Debian 10 / Buster is using iptables >= 1.8, which operates in NFT mode by default.

I found two solutions. One is to install arptables and ebtables as part of the base packages, and then use something like this to force legacy mode:

      - name: Enabling iptables-legacy mode.
        become: yes
        shell: >
            update-alternatives --set {{ item.name }} /usr/sbin/{{ item.name }}-legacy
        with_items:
            - { name: "iptables" }
            - { name: "ip6tables" }
            - { name: "arptables" }
            - { name: "ebtables" }

The other requires Calico v3.8.1 which added support for this version of iptables. For this to work you must set FELIX_IPTABLESBACKEND=NFT. I'm not great at Ansible, so I came up with this:

      - name: Enable nftables backend for Calico.
        blockinfile:
            path: /tmp/calico.yml
            insertbefore: '^\s*securityContext\:'
            block: |4
                            - name: FELIX_IPTABLESBACKEND
                              value: "NFT"

That wouldn't work for like flannel though, I think. Either way, I tested both solutions and they both provide pod to pod communication. I deployed MetalLB on top and it could communicate with the apiserver (which it failed to do before, which is how I noticed all of this).

Ubuntu hanging after kernal panic

Rolling this with an ubuntu image (of any kind) causes it to hang after kernal panic. this looks to be related to what's in this:
https://kb.vmware.com/s/article/52683
Thread.

Basically, if you don't start the VM with a serial port, it will get stuck in kernal panic. Solving this can be done with qm set vmid --serial 0 or via doing it in the UI during the process before the reboot happens

Disk resize error

deploy_qcow2_vms.yml (line 78):

qm resize {{ item.id }} scsi0 {{ item.size }}

This resizing works, but somehow ProxMox doesn't recognize or report the change and Ansible doesn't see it and fails the task. I find if I wait a few minutes, ProxMox (and the dashboard) catch up and show the proper resized value. I get past it by waiting or manually adding 1G to each scsi0 disk in the ProxMox dashboard, and then restarting the playbook after the resize task. All's well from there.

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.