KubernetesCluster {AzureContainers}R Documentation

Kubernetes cluster class

Description

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.

Methods

The following methods are available, in addition to those provided by the AzureRMR::az_resource class:

Initialization

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.

Secrets

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:

Kubectl and helm

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:

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.

See Also

aks, call_kubectl, call_helm

Kubectl commandline reference

Examples

## 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)

[Package AzureContainers version 1.3.2 Index]