KubernetesCluster {AzureContainers} | R Documentation |
Class representing a Kubernetes cluster. Note that this class can be used to interface with any Docker registry that supports the HTTP V2 API, not just those created via the Azure Container Registry service. Use the kubernetes_cluster function to instantiate new objects of this class.
The following methods are available, in addition to those provided by the AzureRMR::az_resource class:
new(...)
: Initialize a new registry object. See 'Initialization' below.
create_registry_secret(registry, secret_name, email)
: Provide authentication secret for a Docker registry. See 'Secrets' below.
delete_registry_secret(secret_name)
: Delete a registry authentication secret.
create(file, ...)
: Creates a deployment or service from a file, using kubectl create -f
.
get(type, ...)
: Get information about resources, using kubectl get
.
run(name, image, ...)
: Run an image using kubectl run --image
.
expose(name, type, file, ...)
: Expose a service using kubectl expose
. If the file
argument is provided, read service information from there.
delete(type, name, file, ...)
: Delete a resource (deployment or service) using kubectl delete
. If the file
argument is provided, read resource information from there.
apply(file, ...)
: Apply a configuration file, using kubectl apply -f
.
show_dashboard(port, ...)
: Display the cluster dashboard. By default, use local port 30000.
kubectl(cmd, ...)
: Run an arbitrary kubectl
command on this cluster. Called by the other methods above.
helm(cmd, ...)
: Run a helm
command on this cluster.
The new()
method takes one argument: config
, the name of the file containing the configuration details for the cluster. This should be a YAML or JSON file in the standard Kubernetes configuration format. Set this to NULL to use the default ~/.kube/config
file.
The recommended way to allow a cluster to authenticate with a Docker registry is to give its service principal the appropriate role-based access. However, you can also authenticate with a username and password. To do this, call the create_registry_secret
method with the following arguments:
registry
: An object of class either acr representing an Azure Container Registry service, or DockerRegistry representing the registry itself.
secret_name
: The name to give the secret. Defaults to the name of the registry server.
email
: The email address for the Docker registry.
The methods for this class call the kubectl
and helm
commandline tools, passing the --config
option to specify the configuration information for the cluster. This allows all the features supported by Kubernetes to be available immediately and with a minimum of effort, although it does require that the tools be installed. The returned object from a call to kubectl
or helm
will contain the following components:
status
: The exit status. If this is NA
, then the process was killed and had no exit status.
stdout
: The standard output of the command, in a character scalar.
stderr
: The standard error of the command, in a character scalar.
timeout
: Whether the process was killed because of a timeout.
cmdline
: The command line.
The first four components are from processx::run
; AzureContainers adds the last to make it easier to construct scripts that can be run outside R.
## Not run:
rg <- AzureRMR::get_azure_login()$
get_subscription("subscription_id")$
get_resource_group("rgname")
# get the cluster endpoint
kubclus <- rg$get_aks("mycluster")$get_cluster()
# get registry authentication secret
kubclus$create_registry_secret(rg$get_acr("myregistry"))
# deploy a service
kubclus$create("deployment.yaml")
# deploy a service from an Internet URL
kubclus$create("https://example.com/deployment.yaml")
# can also supply the deployment parameters inline
kubclus$create("
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: model1
spec:
replicas: 1
template:
metadata:
labels:
app: model1
spec:
containers:
- name: model1
image: myregistry.azurecr.io/model1
ports:
- containerPort: 8000
imagePullSecrets:
- name: myregistry.azurecr.io
---
apiVersion: v1
kind: Service
metadata:
name: model1-svc
spec:
selector:
app: model1
type: LoadBalancer
ports:
- protocol: TCP
port: 8000")
# track status
kubclus$get("deployment")
kubclus$get("service")
## End(Not run)