kOps
repository·master·Indexed 12 days ago
https://github.com/kubernetes/kopsA tool for managing production-grade Kubernetes clusters that automates the provisioning of cloud infrastructure and the lifecycle management of clusters, including creation, upgrades, and maintenance.
What's inside kOps
- kOps (Kubernetes Operations) is a tool designed to automate the creation, destruction, upgrading, and maintenance of production-grade, highly available Kubernetes clusters. It handles both the Kubernetes cluster lifecycle and the provisioning of the underlying cloud infrastructure. It operates on a state-sync model, which enables dry-runs and ensures idempotency in cluster operations.
What is the Discovery Service?
masterThe Discovery Service is a public service that emulates a Kubernetes API. It uses mTLS for authentication and provides "Universe" isolation. It is used to manageDiscoveryEndpointresources and serve OIDC discovery information for external systems like AWS IAM.Use cloudmock to mock CloudProvider APIs
masterThe
cloudmockpackage provides a mock implementation of the CloudProvider APIs. It is designed to allow testing of code that interacts with cloud providers without creating actual physical resources.Key characteristics:
- Stateful Simulation: While no real resources are created,
cloudmockmaintains internal state. For example, callingCreateVpcwill cause a subsequent call toDescribeVpcsto return the newly created VPC. - Purpose: It enables fast, cost-effective testing of logic that would otherwise require real cloud infrastructure.
- Limitations: The APIs are extensive and most are not implemented. Implemented functions may not handle edge cases or error handling with perfect accuracy.
To use it in an AWS context, you can instantiate a
MockEC2client, which implements theec2iface.EC2APIinterface, allowing it to be swapped in for a real EC2 client in your tests.c := &mockec2.MockEC2{} // c can now be used anywhere an ec2iface.EC2API is required- Stateful Simulation: While no real resources are created,
Key Features of kOps
masterkOps provides several advanced capabilities for managing Kubernetes infrastructure:
- Automated Provisioning: Automates the setup of Highly Available (HA) clusters.
- State-Sync Model: Supports dry-runs and provides idempotency (running the same command multiple times results in the same state without unintended side effects).
- Infrastructure as Code: Ability to generate Terraform configurations.
- Managed Add-ons: Supports zero-config managed Kubernetes add-ons.
- Configuration via API: Uses a YAML Manifest Based API for cluster configuration.
- Templating: Supports templating and dry-run modes for creating manifests.
- Networking: Out-of-the-box support for popular CNI (Container Network Interface) providers.
- Multi-architecture: Supports ARM64 architectures.
- Node Customization: Allows adding containers (as hooks) and files to nodes via a cluster manifest.
Use the kops toolbox for miscellaneous commands
masterThe
kops toolboxcommand provides access to miscellaneous, experimental, or infrequently used commands. These tools are often used for specialized tasks like managing addons, interacting with ClusterAPI, dumping cluster information, enrolling machines, or generating cluster templates and instance-group specs.To see all available toolbox subcommands, run
kops toolbox --help.kops toolbox --helpUse the kops CLI
masterkOps (Kubernetes Operations) is a command-line tool used to create, destroy, upgrade, and maintain production-grade, highly available Kubernetes clusters. It is often described as 'kubectl for clusters'.
Currently, AWS is officially supported, while DigitalOcean and OpenStack are in beta support.
Experimental Cluster API (CAPI) Integration Overview
masterThis integration is an experimental attempt to plug in a custom bootstrap provider, enabling Cluster API (CAPI) nodes to join a kOps cluster.
Warning: This feature is experimental, not production-ready, and is currently considered unstable.
Use an Addons index for versioned manifests
masterIf you need a single entry in
spec.addonsto manage multiple versioned manifests, you can use a kOpsAddonsindex. AnAddonsindex defines a collection of addons, each with a name, version, selector, and a manifest path.The manifest path in an
Addonsindex is relative to the index file itself. For example, if your index file isaddon.yaml, a manifest path offoo.addons.org.io/v0.0.1.yamlexpects the file to exist at./foo.addons.org.io/v0.0.1.yamlrelative to the index.Example
Addonsindex structure:kind: Addons metadata: name: example spec: addons: - name: foo.addons.org.io version: 0.0.1 selector: k8s-addon: foo.addons.org.io manifest: foo.addons.org.io/v0.0.1.yaml - name: bar.addons.org.io version: 0.0.1 selector: k8s-addon: bar.addons.org.io manifest: bar.addons.org.io/v0.0.1.yamlExpected file layout:
addon.yaml foo.addons.org.io v0.0.1.yaml bar.addons.org.io v0.0.1.yamlManage kOps clusters via Continuous Integration
masterInstead of using interactive commands like
kops create clusterorkops edit cluster, you can manage clusters entirely in a CI environment using kOps' declarative manifests. By storing cluster and instance group manifests in version control, you gain:- Reviewable Changes: Cluster changes are made through commits and Merge Requests rather than local workstation commands.
- Collision Avoidance: Prevents simultaneous changes from multiple team members.
- Audit Trails: Provides a centralized view and history of all kOps commands executed.
- Safe Upgrades: You can upgrade kOps by downloading a newer version in the CI environment and running a new pipeline, allowing changes to be reviewed and tested on non-production environments before applying them to production.
Understand the role of etcd-manager
masterIn a kOps cluster,
etcd-managerensures the persistence and availability of the etcd cluster. Because kOps uses a static cluster configuration with persistent volumes (like AWS EBS),etcd-managerperforms the following tasks:- Volume Discovery: It identifies the specific volumes containing etcd data using cloud tags.
- Mounting: It mounts these volumes onto the control-plane node where the manager is running.
- Process Management: It runs the
etcdprocess as a child process on that node.
This mechanism allows the system to self-heal: if a master node fails, the AutoScaling Group/Managed Instance Group will replace it, and
etcd-managerwill ensure the etcd data volumes are re-attached and the process restarted.How kOps manages Karpenter EC2NodeClass and NodePool resources
masterWhen an InstanceGroup is configured with
spec.manager: Karpenter, kOps automatically generates and manages two Kubernetes resources via thekarpenter.shaddon:EC2NodeClass: Configures the AWS-specific settings. kOps maps the following from the InstanceGroup:amiFamily: Custom- InstanceGroup image $\rightarrow$
amiSelectorTerms spec.rootVolume$\rightarrow$blockDeviceMappings- Node instance profile and security groups
- Subnets tagged for the InstanceGroup
- Nodeup bootstrap script $\rightarrow$
userData spec.kubeletsettings that affect scheduling (maxPods,systemReserved,kubeReserved) are mapped toEC2NodeClass.spec.kubelet.
NodePool: Defines the scaling logic. It references the generatedEC2NodeClassand includes:- Linux as a requirement
- Instance type and capacity type requirements from the InstanceGroup
- Safe node labels and taints from the InstanceGroup
NodePool.spec.limits.nodes(mapped frommaxSizeif using static mode)
These objects are named after the InstanceGroup and are pruned automatically when the InstanceGroup is removed.
Supported Cloud Providers in kOps
masterkOps supports various cloud platforms with different levels of stability:
- Officially Supported: AWS (Amazon Web Services) and GCP (Google Cloud Platform).
- Beta Support: DigitalOcean, Hetzner, and OpenStack.
- Alpha Support: Azure.