kubernetes-upgrader

module
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 2, 2023 License: Apache-2.0

README

kubernetes-upgrader

A set of Kubernetes controllers to automate Kubernetes clusters upgrade using Cluster API's ClusterClass.

Description

This project is a set of Kubernetes controllers that build Kubernetes machine images using upstream image-builder, and then use those images to upgrade Kubernetes clusters that are using Cluster API's ClusterClass.

This should work with any Infrastructure provider supported by image-builder, but it was only tested with vSphere's CAPV.

Getting Started

You’ll need a Kubernetes cluster to run against. You can use KIND to get a local cluster for testing, or run against a remote cluster. Note: Your controller will automatically use the current context in your kubeconfig file (i.e. whatever cluster kubectl cluster-info shows).

This will deploy the controllers and a sample to build a vSphere OVA, read the upstream docs on how to configure the vSphere provider.

  1. Deploy the CRDs and the controllers:

    kubectl apply -f https://github.com/dkoshkin/kubernetes-upgrader/releases/latest/download/components.yaml
    
  2. Create a Secret with vSphere credentials:

    cat << 'EOF' > vsphere.json
    {
      "vcenter_server":"$VSPHERE_SERVER",
      "insecure_connection": "true",
      "username":"$VSPHERE_USERNAME",
      "password":"$VSPHERE_PASSWORD",
      "vsphere_datacenter": "$VSPHERE_DATACENTER",
      "cluster": "$VSPHERE_CLUSTER",
      "datastore":"$VSPHERE_DATASTORE",
      "folder": "$VSPHERE_TEMPLATE_FOLDER",
      "network": "$VSPHERE_NETWORK",
      "convert_to_template": "true"
    }
    EOF
    kubectl create secret generic image-builder-vsphere-vars --from-file=vsphere.json
    
  3. Deploy the samples:

    kubectl apply -f https://github.com/dkoshkin/kubernetes-upgrader/releases/latest/download/sample-with-job-template.yaml
    
  4. The controller will create a Job to build the image, after some time you should see the image in the vSphere UI. Check the status of KubernetesMachineImage to see if the image was successfully built:

    kubectl get KubernetesMachineImage -o yaml
    

    You should see status.ready set to true and spec.imageID set to a newly created OVA template.

For Developers

You’ll need a Kubernetes cluster to run against. You can use KIND to get a local cluster for testing, or run against a remote cluster. Note: Your controller will automatically use the current context in your kubeconfig file (i.e. whatever cluster kubectl cluster-info shows).

The controller deploys a webhook which requires a TLS certificate. The easiest way to get a certificate is to use cert-manager. You can deploy cert-manager using the following command:

kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.12.4/cert-manager.yaml
Running on the cluster
  1. Generated the components manifests and build the image:

    make release-snapshot
    make docker-push IMG=ghcr.io/dkoshkin/kubernetes-upgrader:$(gojq -r '.version' dist/metadata.json)
    
  2. If using a local KIND cluster:

    kind load docker-image ghcr.io/dkoshkin/kubernetes-upgrader:$(gojq -r '.version' dist/metadata.json)
    
  3. Deploy the controller to the cluster with the image specified by IMG:

    make deploy IMG=ghcr.io/dkoshkin/kubernetes-upgrader:$(gojq -r '.version' dist/metadata.json)
    
  4. Deploy the samples:

    kubectl apply -f config/samples/
    
Undeploy controller

UnDeploy the controller from the cluster:

make undeploy
How it works

This project aims to follow the Kubernetes Operator pattern.

It uses Controllers, which provide a reconcile function responsible for synchronizing resources until the desired state is reached on the cluster.

Modifying the API definitions

If you are editing the API definitions, generate the manifests such as CRs or CRDs using:

make manifests

NOTE: Run make help for more information on all potential make targets

More information can be found via the Kubebuilder Documentation

Directories

Path Synopsis
api
v1alpha1
Package v1alpha1 contains API Schema definitions for the kubernetesupgraded v1alpha1 API group +kubebuilder:object:generate=true +groupName=kubernetesupgraded.dimitrikoshkin.com
Package v1alpha1 contains API Schema definitions for the kubernetesupgraded v1alpha1 API group +kubebuilder:object:generate=true +groupName=kubernetesupgraded.dimitrikoshkin.com
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳