mirror of
https://github.com/openshift/openshift-docs.git
synced 2026-02-05 12:46:18 +01:00
76 lines
1.8 KiB
Plaintext
76 lines
1.8 KiB
Plaintext
// Module included in the following assemblies:
|
|
//
|
|
// * virt/virtual_machines/virt-accessing-vm-ssh.adoc
|
|
|
|
:_mod-docs-content-type: PROCEDURE
|
|
[id="virt-adding-public-key-vm-cli_{context}"]
|
|
= Adding a key when creating a VM by using the CLI
|
|
|
|
[role="_abstract"]
|
|
You can add a statically managed public SSH key when you create a virtual machine (VM) by using the command line. The key is added to the VM at first boot.
|
|
|
|
The key is added to the VM as a cloud-init data source. This method separates the access credentials from the application data in the cloud-init user data. This method does not affect cloud-init user data.
|
|
|
|
.Prerequisites
|
|
|
|
* You generated an SSH key pair by running the `ssh-keygen` command.
|
|
* You have installed the {oc-first}.
|
|
|
|
.Procedure
|
|
|
|
. Create a manifest file for a `VirtualMachine` object and a `Secret` object.
|
|
+
|
|
Example manifest:
|
|
+
|
|
[source,yaml]
|
|
----
|
|
include::snippets/virt-static-key.yaml[]
|
|
----
|
|
<1> Specify the `cloudInitNoCloud` data source.
|
|
<2> Specify the `Secret` object name.
|
|
<3> Paste the public SSH key.
|
|
|
|
. Create the `VirtualMachine` and `Secret` objects by running the following command:
|
|
+
|
|
[source,terminal]
|
|
----
|
|
$ oc create -f <manifest_file>.yaml
|
|
----
|
|
|
|
. Start the VM by running the following command:
|
|
+
|
|
[source,terminal]
|
|
----
|
|
$ virtctl start vm example-vm -n example-namespace
|
|
----
|
|
|
|
.Verification
|
|
* Get the VM configuration:
|
|
+
|
|
[source,terminal]
|
|
----
|
|
$ oc describe vm example-vm -n example-namespace
|
|
----
|
|
+
|
|
Example output:
|
|
+
|
|
[source,yaml]
|
|
----
|
|
apiVersion: kubevirt.io/v1
|
|
kind: VirtualMachine
|
|
metadata:
|
|
name: example-vm
|
|
namespace: example-namespace
|
|
spec:
|
|
template:
|
|
spec:
|
|
accessCredentials:
|
|
- sshPublicKey:
|
|
propagationMethod:
|
|
noCloud: {}
|
|
source:
|
|
secret:
|
|
secretName: authorized-keys
|
|
# ...
|
|
----
|