Class NodeSshProxy<TMetadata>
Uses a SSH/SCP connection to provide access to Linux machines to access files, run commands, etc.
note
This is class is not intended to be a general purpose SSH wrapper at this time. It currently assumes that the remote side is running some variant of Linux and it makes some global changes including disabling SUDO password prompts for all users as well as creating some global directories.
Implements
Namespace: Neon.Kube.SSH
Assembly: Neon.Kube.dll
Syntax
public class NodeSshProxy<TMetadata> : LinuxSshProxy<TMetadata>, INodeSshProxy where TMetadata : class
Type Parameters
Name | Description |
---|---|
TMetadata | Defines the metadata type the application wishes to associate with the server.
You may specify |
Remarks
Construct an instance to connect to a specific cluster node. You may specify
TMetadata
to associate application specific information
or state with the instance.
This class includes methods to invoke Linux commands on the node,
Call Dispose() or Disconnect() to close the connection.
note
You can use Clone() to make a copy of a proxy that can be used to perform parallel operations against the same machine.
Constructors
NodeSshProxy(string, IPAddress, SshCredentials, string, int, TextWriter)
Constructs a LinuxSshProxy<TMetadata>.
Declaration
public NodeSshProxy(string name, IPAddress address, SshCredentials credentials, string role = null, int port = 22, TextWriter logWriter = null)
Parameters
Type | Name | Description |
---|---|---|
string | name | The display name for the server. |
IPAddress | address | The private cluster IP address for the server. |
SshCredentials | credentials | The credentials to be used for establishing SSH connections. |
string | role | Optionally specifies one of the NodeRole values identifying what the node does. |
int | port | Optionally overrides the standard SSH port (22). |
TextWriter | logWriter | The optional TextWriter where operation logs will be written. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
Properties
Cluster
Returns the associated ClusterProxy when there is one.
Declaration
public ClusterProxy Cluster { get; set; }
Property Value
Type | Description |
---|---|
ClusterProxy |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown when there is no associated cluster proxy. |
ImageType
Indicates the type of node image type. This is stored in the /etc/neonkube/image-type file.
Declaration
public KubeImageType ImageType { get; set; }
Property Value
Type | Description |
---|---|
KubeImageType |
ImageVersion
Indicates the NEONKUBE node image version. This is stored in the /etc/neonkube/image-version file. This can be used to ensure that the node image is compatible with the code configuring the cluster.
null
when the /etc/neonkube/image-version file doesn't exist.
Declaration
public SemanticVersion ImageVersion { get; set; }
Property Value
Type | Description |
---|---|
SemanticVersion |
Exceptions
Type | Condition |
---|---|
FormatException | Thrown when the version file could not be parsed. |
NodeDefinition
Returns the associated NodeDefinition metadata when present.
Declaration
public NodeDefinition NodeDefinition { get; }
Property Value
Type | Description |
---|---|
NodeDefinition |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown when there is no associated node definition. |
Role
Returns the node role, one of the NodeRole identifying what the node does.
This may also return null
.
Declaration
public string Role { get; set; }
Property Value
Type | Description |
---|---|
string |
Methods
AllowSshPasswordLogin(bool)
Controls whether SSH login using password authentication is enabled for the node.
Declaration
public void AllowSshPasswordLogin(bool enabled)
Parameters
Type | Name | Description |
---|---|---|
bool | enabled | Pass |
BaseBlacklistFloppy(ISetupController)
Blacklists the Kernel floppy module so it will be disabled when the machine is rebooted.
Declaration
public void BaseBlacklistFloppy(ISetupController controller)
Parameters
Type | Name | Description |
---|---|---|
ISetupController | controller | The setup controller. |
BaseConfigureApt(ISetupController, int, bool)
Configures the APT package manager.
Declaration
public void BaseConfigureApt(ISetupController controller, int packageManagerRetries = 5, bool allowPackageManagerIPv6 = false)
Parameters
Type | Name | Description |
---|---|---|
ISetupController | controller | The setup controller. |
int | packageManagerRetries | Optionally specifies the packager manager retries (defaults to 5). |
bool | allowPackageManagerIPv6 | Optionally prevent the package manager from using IPv6 (defaults to |
BaseConfigureBashEnvironment(ISetupController)
Configures the Debian frontend terminal to non-interactive.
Declaration
public void BaseConfigureBashEnvironment(ISetupController controller)
Parameters
Type | Name | Description |
---|---|---|
ISetupController | controller | The setup controller. |
BaseConfigureDebianFrontend(ISetupController)
Configures the Debian frontend terminal to non-interactive.
Declaration
public void BaseConfigureDebianFrontend(ISetupController controller)
Parameters
Type | Name | Description |
---|---|---|
ISetupController | controller | The setup controller. |
BaseConfigureDnsIPv4Preference(ISetupController)
Ubuntu defaults DNS to prefer IPv6 lookups over IPv4 which can cause performance problems. This method reconfigures DNS to favor IPv4.
Declaration
public void BaseConfigureDnsIPv4Preference(ISetupController controller)
Parameters
Type | Name | Description |
---|---|---|
ISetupController | controller | The setup controller. |
BaseConfigureOpenSsh(ISetupController)
Customizes the OpenSSH configuration on a
Declaration
public void BaseConfigureOpenSsh(ISetupController controller)
Parameters
Type | Name | Description |
---|---|---|
ISetupController | controller | The setup controller. |
BaseCreateKubeFolders(ISetupController)
Create the node folders required by neoneKUBE.
Declaration
public void BaseCreateKubeFolders(ISetupController controller)
Parameters
Type | Name | Description |
---|---|---|
ISetupController | controller | The setup controller. |
BaseDisableCloudInit(ISetupController)
Disables cloud-init.
Declaration
public void BaseDisableCloudInit(ISetupController controller)
Parameters
Type | Name | Description |
---|---|---|
ISetupController | controller | The setup controller. |
BaseDisableDhcp(ISetupController)
Disables DHCP.
Declaration
public void BaseDisableDhcp(ISetupController controller)
Parameters
Type | Name | Description |
---|---|---|
ISetupController | controller | The setup controller. |
BaseDisableSwap(ISetupController)
Disables the Linux memory swap file.
Declaration
public void BaseDisableSwap(ISetupController controller)
Parameters
Type | Name | Description |
---|---|---|
ISetupController | controller | The setup controller. |
BaseInitialize(ISetupController, bool, bool)
Performs low-level initialization of a cluster node.
Declaration
public void BaseInitialize(ISetupController controller, bool upgradeLinux = false, bool patchLinux = true)
Parameters
Type | Name | Description |
---|---|---|
ISetupController | controller | The setup controller. |
bool | upgradeLinux | Optionally upgrade the node's Linux distribution (defaults to |
bool | patchLinux | Optionally apply any available Linux security patches (defaults to |
BaseInstallNeonInit(ISetupController)
Installs the neon-init service which is a poor man's cloud-init like service we use to configure the network and credentials for VMs hosted in non-cloud hypervisors.
Declaration
public void BaseInstallNeonInit(ISetupController controller)
Parameters
Type | Name | Description |
---|---|---|
ISetupController | controller | The setup controller. |
Remarks
Install and configure the [neon-init] service. This is a simple script that is configured to run as a oneshot systemd service before networking is started. This is currently used to configure the node's static IP address configuration on first boot, so we don't need to rely on DHCP (which may not be available in some environments).
[neon-init] is intended to run the first time a node is booted after being created from a template. It checks to see if a special ISO with a configuration script named [neon-init.sh] is inserted into the VMs DVD drive and when present, the script will be executed and the [/etc/neon-init/ready] file will be created to indicate that the service no longer needs to do this for subsequent reboots.
note
The script won't create the [/etc/neon-init] when the script ISO doesn't exist for debugging purposes.
BaseInstallPackages(ISetupController)
Installs the required base image packages.
Declaration
public void BaseInstallPackages(ISetupController controller)
Parameters
Type | Name | Description |
---|---|---|
ISetupController | controller | The setup controller. |
BaseInstallToolScripts(ISetupController)
Installs the tool scripts, making them executable.
note
Any ".sh" file extensions will be removed for ease-of-use.
Declaration
public void BaseInstallToolScripts(ISetupController controller)
Parameters
Type | Name | Description |
---|---|---|
ISetupController | controller | The setup controller. |
BasePatchLinux(ISetupController)
Updates Linux by applying just the outstanding security updates.
Declaration
public void BasePatchLinux(ISetupController controller)
Parameters
Type | Name | Description |
---|---|---|
ISetupController | controller | The setup controller. |
BaseRemovePackages(ISetupController)
Removes unneeded packages.
Declaration
public void BaseRemovePackages(ISetupController controller)
Parameters
Type | Name | Description |
---|---|---|
ISetupController | controller | The setup controller. |
BaseRemoveSnap(ISetupController)
Removes any installed snaps as well as the entire snap infrastructure.
Declaration
public void BaseRemoveSnap(ISetupController controller)
Parameters
Type | Name | Description |
---|---|---|
ISetupController | controller | The setup controller. |
BaseUpgradeLinuxDistribution(ISetupController)
Upgrades the Linux distribution on the node.
Declaration
public void BaseUpgradeLinuxDistribution(ISetupController controller)
Parameters
Type | Name | Description |
---|---|---|
ISetupController | controller | The setup controller. |
Clean(ISetupController)
Cleans a node by removing unnecessary package manager metadata, cached DHCP information, journald logs... and then fills unreferenced file system blocks with zeros so the disk image will or trims the file system (when possible) so the image will compress better.
Declaration
public void Clean(ISetupController controller)
Parameters
Type | Name | Description |
---|---|---|
ISetupController | controller | The setup controller. |
Clone()
Returns a clone of the SSH proxy. This can be useful for situations where you need to be able to perform multiple SSH/SCP operations against the same machine in parallel.
note
This does not clone any attached log writer.
Declaration
public NodeSshProxy<TMetadata> Clone()
Returns
Type | Description |
---|---|
NodeSshProxy<TMetadata> | The cloned NodeSshProxy<TMetadata>. |
ConfigureEnvironmentVariables(ISetupController)
Configures the global environment variables that describe the configuration of the server within the cluster.
Declaration
public void ConfigureEnvironmentVariables(ISetupController controller)
Parameters
Type | Name | Description |
---|---|---|
ISetupController | controller | The setup controller. |
ConfigureJournald(ISetupController)
Configures journald.
Declaration
public void ConfigureJournald(ISetupController controller)
Parameters
Type | Name | Description |
---|---|---|
ISetupController | controller | The setup controller. |
ConfigureSshKey(ISetupController)
Configures a node's host public SSH key during node provisioning.
Declaration
public void ConfigureSshKey(ISetupController controller)
Parameters
Type | Name | Description |
---|---|---|
ISetupController | controller | The setup controller. |
DisableSnap(ISetupController)
Disables the snapd service.
Declaration
public void DisableSnap(ISetupController controller)
Parameters
Type | Name | Description |
---|---|---|
ISetupController | controller | The setup controller. |
GetControlPlaneFiles()
Returns a dictionary of KubeFileDetails holding the control plane files required to provision a new control plane node in the cluster. This dictionary is keyed by the target file name node the node.
Declaration
public Dictionary<string, KubeFileDetails> GetControlPlaneFiles()
Returns
Type | Description |
---|---|
Dictionary<string, KubeFileDetails> | The file dictionary. |
GetIdempotentState(string)
Indicates whether an idempotent action has been completed.
Declaration
public bool GetIdempotentState(string actionId)
Parameters
Type | Name | Description |
---|---|---|
string | actionId | The action ID. |
Returns
Type | Description |
---|---|
bool |
|
GetLog()
Returns the current log for the node.
Declaration
public NodeLog GetLog()
Returns
Type | Description |
---|---|
NodeLog | A NodeLog. |
GetNtpSources()
Returns the NTP time sources to be used by the node.
Declaration
public string GetNtpSources()
Returns
Type | Description |
---|---|
string | The quoted and space separated list of IP address or DNS hostnames for the node's NTP time sources in priority order. |
Remarks
The cluster will be configured such that the first control-plane node (by sorted name) will be the primary timesource for the cluster. All other control-plane and worker nodes will be configured to use the first control-plane node by default. Secondary control-plane nodes will be configured to use the external timesource next so any control-plane can automatically assume these duities.
Worker nodes will be configured to use control-plane node in sorted order but will not be configured to use the external time sources to avoid having large clusters spam the sources.
The nice thing about this is that the cluster will almost always be closely synchronized with the first control-plane with graceful fallback on node failures.
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown when there is no associated cluster proxy. |
InstallHelmChartAsync(ISetupController, string, string, string, string, Dictionary<string, object>, string, TimeSpan)
Installs a prepositioned Helm chart from a control-plane node.
Declaration
public Task InstallHelmChartAsync(ISetupController controller, string chartName, string releaseName = null, string @namespace = "default", string prioritySpec = null, Dictionary<string, object> values = null, string progressMessage = null, TimeSpan timeout = default)
Parameters
Type | Name | Description |
---|---|---|
ISetupController | controller | The setup controller. |
string | chartName | The name of the Helm chart. noteHelm does not allow dashes (-) in chart names but to avoid problems with copy/pasting, we will automatically convert any dashes to underscores before installing the chart. This is also nice because this means that the chart name passed can be the same as the release name in the calling code. |
string | releaseName | Optionally specifies the component release name. |
string | namespace | Optionally specifies the namespace where Kubernetes namespace where the Helm chart should be installed. This defaults to default. |
string | prioritySpec | Optionally specifies the Helm variable and priority class for any pods deployed by the chart. This needs to be specified as: PRIORITYCLASSNAME or VALUENAME=PRIORITYCLASSNAME, where VALUENAME optionally specifies the name of the Helm value and PRIORITYCLASSNAME is one of the priority class names defined by PriorityClass. noteThe priority class will saved as the priorityClassName Helm value when no value name is specified. |
Dictionary<string, object> | values | Optionally specifies Helm chart values. |
string | progressMessage | Optionally specifies progress message. This defaults to |
TimeSpan | timeout | Optionally specifies the timeout. This defaults to 300 seconds. |
Returns
Type | Description |
---|---|
Task | The tracking Task. |
Remarks
NEONKUBE images prepositions the Helm chart files embedded as resources in the Resources/Helm project folder to cluster node images as the /lib/neonkube/helm/charts.zip archive. This method unzips that file to the same folder (if it hasn't been unzipped already) and then installs the helm chart (if it hasn't already been installed).
Exceptions
Type | Condition |
---|---|
KeyNotFoundException | Thrown if the priority class specified by |
InstallNFS(ISetupController)
Installs NFS.
Declaration
public void InstallNFS(ISetupController controller)
Parameters
Type | Name | Description |
---|---|---|
ISetupController | controller | The setup controller. |
InstallProvisionedHelmChart(string, string, string, TimeSpan, List<KeyValuePair<string, object>>)
Installs one of the Helm charts that was pre-positioned on the node VM image. These can be fond in the Helm with a folder for each chart.
note
This command DOES NOT WAIT for the Helm chart to be completely installed and any target services or assets to be running because that does not appear to be reliable. You'll need to explicitly verify that deployment has completed when necessary.
Declaration
public void InstallProvisionedHelmChart(string chartName, string releaseName = null, string @namespace = "default", TimeSpan timeout = default, List<KeyValuePair<string, object>> values = null)
Parameters
Type | Name | Description |
---|---|---|
string | chartName | The Helm chart folder name. |
string | releaseName | Optional component release name. This defaults to |
string | namespace | Optional namespace where Kubernetes namespace where the Helm chart should be installed. This defaults to "default". |
TimeSpan | timeout | Optional timeout. This defaults to unlimited. |
List<KeyValuePair<string, object>> | values | Optional Helm chart value overrides. |
InvokeIdempotent(string, Action)
Invokes a named action on the node if it has never been been performed on the node before.
Declaration
public bool InvokeIdempotent(string actionId, Action action)
Parameters
Type | Name | Description |
---|---|---|
string | actionId | The node-unique action ID. |
Action | action | The action to be performed. |
Returns
Type | Description |
---|---|
bool |
|
Remarks
actionId
must uniquely identify the action on the node.
This may include letters, digits, dashes and periods as well as one or
more forward slashes that can be used to organize idempotent status files
into folders.
This method tracks successful action completion by creating a file on the node at State/ACTION-ID. To ensure idempotency, this method first checks for the existence of this file and returns immediately without invoking the action if it is present.
InvokeIdempotentAsync(string, Func<Task>)
Invokes a named action asynchronously on the node if it has never been been performed on the node before.
Declaration
public Task<bool> InvokeIdempotentAsync(string actionId, Func<Task> action)
Parameters
Type | Name | Description |
---|---|---|
string | actionId | The node-unique action ID. |
Func<Task> | action | The asynchronous action to be performed. |
Returns
Type | Description |
---|---|
Task<bool> |
|
Remarks
actionId
must uniquely identify the action on the node.
This may include letters, digits, dashes and periods as well as one or
more forward slashes that can be used to organize idempotent status files
into folders.
This method tracks successful action completion by creating a file on the node at State/ACTION-ID. To ensure idempotency, this method first checks for the existence of this file and returns immediately without invoking the action if it is present.
LoadImageAsync(NodeImageInfo)
Method to load specific container image onto the the node.
Declaration
public Task LoadImageAsync(NodeImageInfo image)
Parameters
Type | Name | Description |
---|---|---|
NodeImageInfo | image | The image. |
Returns
Type | Description |
---|---|
Task | The tracking Task. |
Log(string)
Declaration
public override void Log(string text)
Parameters
Type | Name | Description |
---|---|---|
string | text |
Overrides
LogFlush()
Declaration
public override void LogFlush()
Overrides
LogLine(string)
Declaration
public override void LogLine(string text)
Parameters
Type | Name | Description |
---|---|---|
string | text |
Overrides
NodeDisableNeonInit(ISetupController)
Disables the neon-init service during cluster setup because it is no longer necessary after the node first boots and its credentials and network settings have been configured.
Declaration
public void NodeDisableNeonInit(ISetupController controller)
Parameters
Type | Name | Description |
---|---|---|
ISetupController | controller | The setup controller. |
NodeInitialize(ISetupController)
Performs low-level node initialization during cluster setup.
Declaration
public void NodeInitialize(ISetupController controller)
Parameters
Type | Name | Description |
---|---|---|
ISetupController | controller | The setup controller. |
NodeInstallCriO(ISetupController, ClusterManifest)
Installs the CRI-O container runtime.
Declaration
public void NodeInstallCriO(ISetupController controller, ClusterManifest clusterManifest)
Parameters
Type | Name | Description |
---|---|---|
ISetupController | controller | The setup controller. |
ClusterManifest | clusterManifest | The cluster manifest. |
NodeInstallHelm(ISetupController)
Installs the Helm client.
Declaration
public void NodeInstallHelm(ISetupController controller)
Parameters
Type | Name | Description |
---|---|---|
ISetupController | controller | The setup controller. |
NodeInstallIPVS(ISetupController)
Installs the necessary packages and configures setup for IPVS.
Declaration
public void NodeInstallIPVS(ISetupController controller)
Parameters
Type | Name | Description |
---|---|---|
ISetupController | controller | The setup controller. |
NodeInstallKubernetes(ISetupController)
Installs the Kubernetes components: kubeadm, kubectl, and kubelet.
Declaration
public void NodeInstallKubernetes(ISetupController controller)
Parameters
Type | Name | Description |
---|---|---|
ISetupController | controller | The setup controller. |
NodeInstallPodman(ISetupController)
Installs the podman CLI for managing CRI-O.
Declaration
public void NodeInstallPodman(ISetupController controller)
Parameters
Type | Name | Description |
---|---|---|
ISetupController | controller | The setup controller. |
NodeInstallTools(ISetupController)
Installs the NEONKUBE related tools to the Bin folder.
Declaration
public void NodeInstallTools(ISetupController controller)
Parameters
Type | Name | Description |
---|---|---|
ISetupController | controller | The setup controller. |
NodeLoadImagesAsync(ISetupController, int, int)
Loads the docker images onto the node. This is used for debug mode only.
Declaration
public Task NodeLoadImagesAsync(ISetupController controller, int downloadParallel = 5, int loadParallel = 2)
Parameters
Type | Name | Description |
---|---|---|
ISetupController | controller | The setup controller. |
int | downloadParallel | The optional limit for parallelism when downloading images from GitHub registry. |
int | loadParallel | The optional limit for parallelism when loading images into the cluster. |
Returns
Type | Description |
---|---|
Task |
PrepareNode(ISetupController)
Initializes a near virgin server with the basic capabilities required for a cluster node.
Declaration
public void PrepareNode(ISetupController controller)
Parameters
Type | Name | Description |
---|---|---|
ISetupController | controller | The setup controller. |
RemoveSwapFile(ISetupController)
Removes the Linux swap file if present.
Declaration
public void RemoveSwapFile(ISetupController controller)
Parameters
Type | Name | Description |
---|---|---|
ISetupController | controller | The setup controller. |
SetIdempotentState(string)
Explicitly indicates that an idempotent action has been completed on the node.
Declaration
public void SetIdempotentState(string actionId)
Parameters
Type | Name | Description |
---|---|---|
string | actionId | The action ID. |
SetupConfigureNtp(ISetupController)
Configures NTP and also installs some tool scripts for managing this.
Declaration
public void SetupConfigureNtp(ISetupController controller)
Parameters
Type | Name | Description |
---|---|---|
ISetupController | controller | The setup controller. |
SetupKubelet(ISetupController)
Configures the kubelet service.
Declaration
public void SetupKubelet(ISetupController controller)
Parameters
Type | Name | Description |
---|---|---|
ISetupController | controller | The setup controller. |
Remarks
note
Kubelet is installed in NodeInstallKubernetes(ISetupController) when configuring the node image and is then configured for the cluster here.
SetupNode(ISetupController, ClusterManifest)
Performs common node configuration.
Declaration
public void SetupNode(ISetupController controller, ClusterManifest clusterManifest)
Parameters
Type | Name | Description |
---|---|---|
ISetupController | controller | The setup controller. |
ClusterManifest | clusterManifest | The cluster manifest. |
SetupPackageProxy(ISetupController)
Configures cluster package manager caching.
Declaration
public void SetupPackageProxy(ISetupController controller)
Parameters
Type | Name | Description |
---|---|---|
ISetupController | controller | The setup controller. |
UpdateLinux(ISetupController, bool)
Upgrades the base Linux distribtion, rebooting the node when required.
Declaration
public void UpdateLinux(ISetupController controller, bool fullUpgrade)
Parameters
Type | Name | Description |
---|---|---|
ISetupController | controller | The setup controller. |
bool | fullUpgrade | Pass |
VerifyNodeOS(ISetupController)
Ensures that the node operating system and version is supported for a NEONKUBE cluster. This faults the node proxy on failure.
Declaration
public bool VerifyNodeOS(ISetupController controller = null)
Parameters
Type | Name | Description |
---|---|---|
ISetupController | controller | Optional setup controller. |
Returns
Type | Description |
---|---|
bool |
|