generated from kubernetes/kubernetes-template-project
-
Notifications
You must be signed in to change notification settings - Fork 403
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
patch: Support for building images on OpenStack
* Support for building images directly in Openstack by utilising the Openstack packer builder. * Supports Ubuntu and Flatcar (only tested on these two OS but could support others) * New "page" in the book to reflect new process Co-authored-by: yankcrime - Nick Jones Co-authored-by: drew-viles - Drew Viles Co-authored-by: okozachenko1203 - Oleksandr Kozachenko Co-authored-by: mitch000001 - Michael Wagner Co-authored-by: mboersma - Matt Boersma
- Loading branch information
1 parent
62265c5
commit eacb6bf
Showing
13 changed files
with
316 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Building Images on OpenStack | ||
|
||
## Hypervisor | ||
|
||
The image is built using OpenStack. | ||
|
||
### Prerequisites for OpenStack builds | ||
|
||
First, check for prerequisites at [Packer docs for the OpenStack builder](https://developer.hashicorp.com/packer/plugins/builders/openstack). | ||
|
||
Also ensure that you have a [Ubuntu 20.04](https://cloud-images.ubuntu.com/focal/current/) or [Ubuntu 22.04](https://cloud-images.ubuntu.com/jammy/current/) cloud image available in your OpenStack instance before continuing as it will need to be referenced. | ||
This build process also supports Flatcar Linux, but only Stable has been tested. | ||
|
||
#### Note | ||
> Other operating systems could be supported and additions are welcome. | ||
## Setup Openstack authentication | ||
Ensure you have set up your method of authentication. See the [examples here](https://docs.openstack.org/python-openstackclient/zed/cli/authentication.html). | ||
You can also check out the [packer builder](https://developer.hashicorp.com/packer/plugins/builders/openstack#configuration-reference) for more information on authentication. | ||
|
||
You should be able to run commands against OpenStack before running this builder, otherwise it will fail. | ||
You can test with a simple command such as `openstack image list`. | ||
|
||
## Building Images | ||
|
||
The build [prerequisites](../capi.md#prerequisites) for using `image-builder` for | ||
building OpenStack images are managed by running: | ||
|
||
```bash | ||
cd image-builder/images/capi | ||
make deps-openstack | ||
``` | ||
|
||
### Define variables for OpenStack build | ||
|
||
Using the [Openstack packer provider](https://developer.hashicorp.com/packer/plugins/builders/openstack), an instance will be deployed and an image built from it. | ||
A certain set of environment variables must be defined in a json file and referenced as shown below in the build example. | ||
|
||
Replace UPPERCASE variables with your values. | ||
```json | ||
{ | ||
"source_image": "OPENSTACK_SOURCE_IMAGE_ID", | ||
"networks": "OPENSTACK_NETWORK_ID", | ||
"flavor": "OPENSTACK_INSTANCE_FLAVOR_NAME", | ||
"floating_ip_network": "OPENSTACK_FLOATING_IP_NETWORK_NAME", | ||
"image_name": "KUBE-UBUNTU", | ||
"image_visibility": "public", | ||
"image_disk_format": "raw", | ||
"volume_type": "", | ||
"ssh_username": "ubuntu" | ||
} | ||
``` | ||
|
||
Check out `images/capi/packer/openstack/packer.json` for more variables such as allowing the use of floating IPs and config drives. | ||
|
||
### Building Image on OpenStack | ||
|
||
From the `images/capi` directory, run `PACKER_VAR_FILES=var_file.json make build-openstack-<DISTRO>`. | ||
|
||
An instance is built in OpenStack from the source image defined. Once completed, the instance is shut down and the image is created. | ||
This image will default to private, however this can be controlled via `image_visibility`. | ||
|
||
For building a ubuntu 22.04-based CAPI image with Kubernetes 1.23.15, run the following commands: | ||
|
||
#### Example | ||
```bash | ||
$ git clone https://github.com/kubernetes-sigs/image-builder.git | ||
$ cd image-builder/images/capi/ | ||
$ make deps-openstack | ||
$ PACKER_VAR_FILES=var_file.json make build-openstack-ubuntu-2204 | ||
``` | ||
|
||
The resulting image will be named `ubuntu-2204-kube-v1.23.15` based on the following format: `<OS>-kube-<KUBERNETES_SEMVER>`. | ||
|
||
This can be modified by overriding the `image_name` variable if required. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Copyright 2020 The Kubernetes Authors. | ||
|
||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
|
||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
--- | ||
- name: Install cloud-init packages | ||
apt: | ||
name: "{{ packages }}" | ||
state: present | ||
force_apt_get: yes | ||
vars: | ||
packages: | ||
- cloud-init | ||
- cloud-guest-utils | ||
- cloud-initramfs-copymods | ||
- cloud-initramfs-dyn-netconf | ||
when: ansible_os_family == "Debian" | ||
|
||
- name: Disable Hyper-V KVP protocol daemon on Ubuntu | ||
systemd: | ||
name: hv-kvp-daemon | ||
state: stopped | ||
enabled: false | ||
when: ansible_os_family == "Debian" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# See the OWNERS docs at https://go.k8s.io/owners | ||
|
||
approvers: | ||
- cluster-api-openstack-maintainers | ||
|
||
reviewers: | ||
- cluster-api-openstack-maintainers | ||
- image-builder-openstack-reviewers | ||
- image-builder-openstack-maintainers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"ansible_extra_vars": "ansible_python_interpreter=/opt/bin/python", | ||
"build_name": "flatcar", | ||
"crictl_source_type": "http", | ||
"distro_name": "flatcar", | ||
"kubernetes_cni_source_type": "http", | ||
"kubernetes_source_type": "http", | ||
"source_image": "flatcar", | ||
"systemd_prefix": "/etc/systemd", | ||
"sysusr_prefix": "/opt", | ||
"sysusrlocal_prefix": "/opt" | ||
} |
Oops, something went wrong.