copyright | lastupdated | keywords | subcollection | ||
---|---|---|---|---|---|
|
2019-09-03 |
kubernetes, iks, ibmcloud, ic, ks, kubectl, api |
containers |
{:new_window: target="_blank"} {:shortdesc: .shortdesc} {:screen: .screen} {:pre: .pre} {:table: .aria-labeledby="caption"} {:codeblock: .codeblock} {:tip: .tip} {:note: .note} {:important: .important} {:deprecated: .deprecated} {:download: .download} {:preview: .preview}
{: #cs_api_install}
You can use the {{site.data.keyword.containerlong}} API to create and manage your community Kubernetes or OpenShift clusters. To use the CLI, see Setting up the CLI. {:shortdesc}
{: #api_about}
The {{site.data.keyword.containerlong_notm}} API automates the provisioning and management of {{site.data.keyword.cloud_notm}} infrastructure resources for your Kubernetes or OpenShift clusters so that your apps have the compute, networking, and storage resources that they need to serve your users. {:shortdesc}
The API is versioned to support the different infrastructure providers that are available for you to create clusters. For more information, see Overview of Classic and VPC infrastructure providers.
You can use the version two (v2
) API to manage both classic and VPC on Classic clusters. The v2
API is designed to avoid breaking existing functionality when possible. However, make sure that you review the following differences between the v1
and v2
API.
Area | v1 API | v2 API |
---|---|---|
API endpoint | https://containers.cloud.ibm.com/global/v1 | https://containers.cloud.ibm.com/global/v2 |
API reference docs | [`https://containers.cloud.ibm.com/global/swagger-global-api/` ![External link icon](../icons/launch-glyph.svg "External link icon")](https://containers.cloud.ibm.com/global/swagger-global-api/) | |
API architectural style | Representational state transfer (REST) that focuses on resources that you interact with through HTTP methods such as `GET`, `POST`, `PUT`, `PATCH`, and `DELETE`. | Remote procedure calls (RPC) that focus on actions through only `GET` and `POST` HTTP methods. |
Supported container platforms | Use the {{site.data.keyword.containerlong_notm}} API to manage your {{site.data.keyword.cloud_notm}} infrastructure resources, such as worker nodes, for **both community Kubernetes and OpenShift clusters**. | VPC clusters are available for **only community Kubernetes clusters**, not OpenShift clusters. As such, provider-specific `v2` API calls against OpenShift clusters fail. |
Kubernetes API | To use the Kubernetes API to manage Kubernetes resources within the cluster, such as pods or namespaces, see [Working with your cluster by using the Kubernetes API](#kube_api). | |
Supported infrastructure providers | `classic` | `vpc` and `classic`
|
`GET` responses | The `GET` method for a collection of resources (such as `GET v1/clusters`) returns the same details for each resource in the list as a `GET` method for an individual resource (such as `GET v1/clusters/{idOrName}`). | To return responses faster, the v2 `GET` method for a collection of resources (such as `GET v2/clusters`) returns only a subset of information that is detailed in a `GET` method for an individual resource (such as `GET v2/clusters/{idOrName}`).
Some list responses include a providers property to identify whether the returned item applies to classic or VPC infrastructure. For example, the `GET zones` list returns some results such as `mon01` that are available only in the classic infrastructure provider, while other results such as `us-south-01` are available only in the VPC infrastructure provider. |
Cluster, worker node, and worker-pool responses | Responses include only information that is specific to the classic infrastructure provider, such as the VLANs in `GET` cluster and worker responses. | The information that is returned varies depending on the infrastructure provider. For such provider-specific responses, you can specify the provider in your request. For example, VPC clusters do not return VLAN information since they do not have VLANs. Instead, they return subnet and CIDR network information. |
{: #cs_api}
You can use the {{site.data.keyword.containerlong_notm}} API to automate the creation, deployment, and management of your Kubernetes clusters. {:shortdesc}
The {{site.data.keyword.containerlong_notm}} API requires header information that you must provide in your API request and that can vary depending on the API that you want to use. To determine what header information is needed for your API, see the {{site.data.keyword.containerlong_notm}} API documentation .
To authenticate with {{site.data.keyword.containerlong_notm}}, you must provide an {{site.data.keyword.cloud_notm}} Identity and Access Management (IAM) token that is generated with your {{site.data.keyword.cloud_notm}} credentials and that includes the {{site.data.keyword.cloud_notm}} account ID where the cluster was created. Depending on the way you authenticate with {{site.data.keyword.cloud_notm}}, you can choose between the following options to automate the creation of your {{site.data.keyword.cloud_notm}} IAM token.
You can also use the API swagger JSON file to generate a client that can interact with the API as part of your automation work. {: tip}
{{site.data.keyword.cloud_notm}} ID | My options |
---|---|
Unfederated ID |
|
Federated ID |
|
-
Create your {{site.data.keyword.cloud_notm}} IAM access token. The body information that is included in your request varies based on the {{site.data.keyword.cloud_notm}} authentication method that you use.
POST https://iam.bluemix.net/identity/token
{: codeblock}
Input parameters to get IAM tokens. Input parameters Values Header - Content-Type: application/x-www-form-urlencoded
- Authorization: Basic Yng6Yng=
Note:
Yng6Yng=
equals the URL-encoded authorization for the user name bx and the password bx.
Body for {{site.data.keyword.cloud_notm}} user name and password - `grant_type: password`
- `response_type: cloud_iam uaa`
- `username`: Your {{site.data.keyword.cloud_notm}} user name.
- `password`: Your {{site.data.keyword.cloud_notm}} password.
- `uaa_client_id: cf`
- `uaa_client_secret:`
Note: Add theuaa_client_secret
key with no value specified.
Body for {{site.data.keyword.cloud_notm}} API keys - `grant_type: urn:ibm:params:oauth:grant-type:apikey`
- `response_type: cloud_iam uaa`
- `apikey`: Your {{site.data.keyword.cloud_notm}} API key
- `uaa_client_id: cf`
- `uaa_client_secret:`
Note: Add theuaa_client_secret
key with no value specified.
Body for {{site.data.keyword.cloud_notm}} one-time passcode grant_type: urn:ibm:params:oauth:grant-type:passcode
- `response_type: cloud_iam uaa`
- `passcode`: Your {{site.data.keyword.cloud_notm}} one-time passcode. Run `ibmcloud login --sso` and follow the instructions in your CLI output to retrieve your one-time passcode by using your web browser.
- `uaa_client_id: cf`
- `uaa_client_secret:`
Note: Add theuaa_client_secret
key with no value specified.
Example output for using an API key:
{ "access_token": "<iam_access_token>", "refresh_token": "<iam_refresh_token>", "uaa_token": "<uaa_token>", "uaa_refresh_token": "<uaa_refresh_token>", "token_type": "Bearer", "expires_in": 3600, "expiration": 1493747503 "scope": "ibm openid" }
{: screen}
You can find the {{site.data.keyword.cloud_notm}} IAM token in the access_token field of your API output. Note the {{site.data.keyword.cloud_notm}} IAM token to retrieve additional header information in the next steps.
-
Retrieve the ID of the {{site.data.keyword.cloud_notm}} account that you want to work with. Replace
<iam_access_token>
with the {{site.data.keyword.cloud_notm}} IAM token that you retrieved from the access_token field of your API output in the previous step. In your API output, you can find the ID of your {{site.data.keyword.cloud_notm}} account in the resources.metadata.guid field.GET https://accountmanagement.ng.bluemix.net/v1/accounts
{: codeblock}
Input parameters to get an {{site.data.keyword.cloud_notm}} account ID. Input parameters Values Headers Content-Type: application/json
- `Authorization: bearer `
Accept: application/json
Example output:
{ "total_results": 3, "total_pages": 1, "prev_url": null, "next_url": null, "resources": { "metadata": { "guid": "<account_ID>", "url": "/v1/accounts/<account_ID>", "created_at": "2016-01-07T18:55:09.726Z", "updated_at": "2017-04-28T23:46:03.739Z", "origin": "BSS" ...
{: screen}
-
Generate a new {{site.data.keyword.cloud_notm}} IAM token that includes your {{site.data.keyword.cloud_notm}} credentials and the account ID that you want to work with.
If you use an {{site.data.keyword.cloud_notm}} API key, you must use the {{site.data.keyword.cloud_notm}} account ID the API key was created for. To access clusters in other accounts, log into this account and create an {{site.data.keyword.cloud_notm}} API key that is based on this account. {: note}
POST https://iam.bluemix.net/identity/token
{: codeblock}
Input parameters to get IAM tokens. Input parameters Values Header - `Content-Type: application/x-www-form-urlencoded`
- `Authorization: Basic Yng6Yng=`
Note:
Yng6Yng=
equals the URL-encoded authorization for the user name bx and the password bx.
Body for {{site.data.keyword.cloud_notm}} user name and password - `grant_type: password`
- `response_type: cloud_iam uaa`
- `username`: Your {{site.data.keyword.cloud_notm}} user name.
- `password`: Your {{site.data.keyword.cloud_notm}} password.
- `uaa_client_ID: cf`
- `uaa_client_secret:`
Note: Add theuaa_client_secret
key with no value specified. - `bss_account`: The {{site.data.keyword.cloud_notm}} account ID that you retrieved in the previous step.
Body for {{site.data.keyword.cloud_notm}} API keys - `grant_type: urn:ibm:params:oauth:grant-type:apikey`
- `response_type: cloud_iam uaa`
- `apikey`: Your {{site.data.keyword.cloud_notm}} API key.
- `uaa_client_ID: cf`
- `uaa_client_secret:`
Note: Add theuaa_client_secret
key with no value specified. - `bss_account`: The {{site.data.keyword.cloud_notm}} account ID that you retrieved in the previous step.
Body for {{site.data.keyword.cloud_notm}} one-time passcode - `grant_type: urn:ibm:params:oauth:grant-type:passcode`
- `response_type: cloud_iam uaa`
- `passcode`: Your {{site.data.keyword.cloud_notm}} passcode.
- `uaa_client_ID: cf`
- `uaa_client_secret:`
Note: Add theuaa_client_secret
key with no value specified. - `bss_account`: The {{site.data.keyword.cloud_notm}} account ID that you retrieved in the previous step.
Example output:
{ "access_token": "<iam_token>", "refresh_token": "<iam_refresh_token>", "token_type": "Bearer", "expires_in": 3600, "expiration": 1493747503 }
{: screen}
You can find the {{site.data.keyword.cloud_notm}} IAM token in the access_token and the refresh token in the refresh_token field of your API output.
-
List available {{site.data.keyword.containerlong_notm}} regions and select the region that you want to work in. Use the IAM access token and refresh token from the previous step to build your header information.
GET https://containers.cloud.ibm.com/v1/regions
{: codeblock}
Input parameters to retrieve {{site.data.keyword.containerlong_notm}} regions. Input parameters Values Header - `Authorization: bearer `
- `X-Auth-Refresh-Token: `
Example output:
{ "regions": [ { "name": "ap-north", "alias": "jp-tok", "cfURL": "api.au-syd.bluemix.net", "freeEnabled": false }, { "name": "ap-south", "alias": "au-syd", "cfURL": "api.au-syd.bluemix.net", "freeEnabled": true }, { "name": "eu-central", "alias": "eu-de", "cfURL": "api.eu-de.bluemix.net", "freeEnabled": true }, { "name": "uk-south", "alias": "eu-gb", "cfURL": "api.eu-gb.bluemix.net", "freeEnabled": true }, { "name": "us-east", "alias": "us-east", "cfURL": "api.ng.bluemix.net", "freeEnabled": false }, { "name": "us-south", "alias": "us-south", "cfURL": "api.ng.bluemix.net", "freeEnabled": true } ] }
{: screen}
-
List all clusters in the {{site.data.keyword.containerlong_notm}} region that you selected. If you want to run Kubernetes API requests against your cluster, make sure to note the id and region of your cluster.
GET https://containers.cloud.ibm.com/v1/clusters
{: codeblock}
Input parameters to work with the {{site.data.keyword.containerlong_notm}} API. Input parameters Values Header - `Authorization: bearer `
- `X-Auth-Refresh-Token: `
- `X-Region: `
-
Review the {{site.data.keyword.containerlong_notm}} API documentation to find a list of supported APIs.
{: #kube_api}
You can use the Kubernetes API to interact with your cluster in {{site.data.keyword.containerlong_notm}}. {: shortdesc}
The following instructions require public network access in your cluster to connect to the public service endpoint of your Kubernetes master. {: note}
-
Follow the steps in Automating cluster deployments with the API to retrieve your {{site.data.keyword.cloud_notm}} IAM access token, refresh token, the ID of the cluster where you want to run Kubernetes API requests, and the {{site.data.keyword.containerlong_notm}} region where your cluster is located.
-
Retrieve an {{site.data.keyword.cloud_notm}} IAM delegated refresh token.
POST https://iam.bluemix.net/identity/token
{: codeblock}
Input parameters to get an IAM delegated refresh token. Input parameters Values Header - `Content-Type: application/x-www-form-urlencoded`
- `Authorization: Basic Yng6Yng=`
Note:Yng6Yng=
equals the URL-encoded authorization for the user name bx and the password bx. - `cache-control: no-cache`
Body - `delegated_refresh_token_expiry: 600`
- `receiver_client_ids: kube`
- `response_type: delegated_refresh_token`
- `refresh_token`: Your {{site.data.keyword.cloud_notm}} IAM refresh token.
- `grant_type: refresh_token`
Example output:
{ "delegated_refresh_token": <delegated_refresh_token> }
{: screen}
-
Retrieve an {{site.data.keyword.cloud_notm}} IAM ID, IAM access, and IAM refresh token by using the delegated refresh token from the previous step. In your API output, you can find the IAM ID token in the id_token field, the IAM access token in the access_token field, and the IAM refresh token in the refresh_token field.
POST https://iam.bluemix.net/identity/token
{: codeblock}
Input parameters to get IAM ID and IAM access tokens. Input parameters Values Header - `Content-Type: application/x-www-form-urlencoded`
- `Authorization: Basic a3ViZTprdWJl`
Note:a3ViZTprdWJl
equals the URL-encoded authorization for the user namekube
and the passwordkube
. - `cache-control: no-cache`
Body - `refresh_token`: Your {{site.data.keyword.cloud_notm}} IAM delegated refresh token.
- `grant_type: urn:ibm:params:oauth:grant-type:delegated-refresh-token`
Example output:
{ "access_token": "<iam_access_token>", "id_token": "<iam_id_token>", "refresh_token": "<iam_refresh_token>", "token_type": "Bearer", "expires_in": 3600, "expiration": 1553629664, "scope": "ibm openid containers-kubernetes" }
{: screen}
-
Retrieve the public URL of your Kubernetes master by using the IAM access token, the IAM ID token, the IAM refresh token, and the {{site.data.keyword.containerlong_notm}} region that your cluster is in. You can find the URL in the
publicServiceEndpointURL
of your API output.GET https://containers.cloud.ibm.com/v1/clusters/<cluster_ID>
{: codeblock}
Input parameters to get the public service endpoint for your Kubernetes master. Input parameters Values Header - `Authorization`: Your {{site.data.keyword.cloud_notm}} IAM access token.
- `X-Auth-Refresh-Token`: Your {{site.data.keyword.cloud_notm}} IAM refresh token.
- `X-Region`: The {{site.data.keyword.containerlong_notm}} region of your cluster that you retrieved with the `GET https://containers.cloud.ibm.com/v1/clusters` API in [Automating cluster deployments with the API](#cs_api).
Path `:` The ID of your cluster that you retrieved with the `GET https://containers.cloud.ibm.com/v1/clusters` API in [Automating cluster deployments with the API](#cs_api). Example output:
{ "location": "Dallas", "dataCenter": "dal10", "multiAzCapable": true, "vlans": null, "worker_vlans": null, "workerZones": [ "dal10" ], "id": "1abc123b123b124ab1234a1a12a12a12", "name": "mycluster", "region": "us-south", ... "publicServiceEndpointURL": "https://c7.us-south.containers.cloud.ibm.com:27078" }
{: screen}
-
Run Kubernetes API requests against your cluster by using the IAM ID token that you retrieved earlier. For example, list the Kubernetes version that runs in your cluster.
If you enabled SSL certificate verification in your API test framework, make sure to disable this feature. {: tip}
GET <publicServiceEndpointURL>/version
{: codeblock}
Input parameters to view the Kubernetes version that runs in your cluster. Input parameters Values Header `Authorization: bearer ` Path ``: The **`publicServiceEndpointURL`** of your Kubernetes master that you retrieved in the previous step. Example output:
{ "major": "1", "minor": "13", "gitVersion": "v1.13.4+IKS", "gitCommit": "c35166bd86eaa91d17af1c08289ffeab3e71e11e", "gitTreeState": "clean", "buildDate": "2019-03-21T10:08:03Z", "goVersion": "go1.11.5", "compiler": "gc", "platform": "linux/amd64" }
{: screen}
-
Review the Kubernetes API documentation to find a list of supported APIs for the latest Kubernetes version. Make sure to use the API documentation that matches the Kubernetes version of your cluster. If you do not use the latest Kubernetes version, append your version at the end of the URL. For example, to access the API documentation for version 1.12, add
v1.12
.
Refreshing {{site.data.keyword.cloud_notm}} IAM access tokens and obtaining new refresh tokens with the API
{: #cs_api_refresh}
Every {{site.data.keyword.cloud_notm}} Identity and Access Management (IAM) access token that is issued via the API expires after one hour. You must refresh your access token regularly to assure access to the {{site.data.keyword.cloud_notm}} API. You can use the same steps to obtain a new refresh token. {:shortdesc}
Before you begin, make sure that you have an {{site.data.keyword.cloud_notm}} IAM refresh token or an {{site.data.keyword.cloud_notm}} API key that you can use to request a new access token.
- Refresh token: Follow the instructions in Automating the cluster creation and management process with the {{site.data.keyword.cloud_notm}} API.
- API key: Retrieve your {{site.data.keyword.cloud_notm}} API key as follows.
- From the menu bar, click Manage > Access (IAM).
- Click the Users page and then select yourself.
- In the API keys pane, click Create an IBM Cloud API key.
- Enter a Name and Description for your API key and click Create.
- Click Show to see the API key that was generated for you.
- Copy the API key so that you can use it to retrieve your new {{site.data.keyword.cloud_notm}} IAM access token.
Use the following steps if you want to create an {{site.data.keyword.cloud_notm}} IAM token or if you want to obtain a new refresh token.
-
Generate a new {{site.data.keyword.cloud_notm}} IAM access token by using the refresh token or the {{site.data.keyword.cloud_notm}} API key.
POST https://iam.bluemix.net/identity/token
{: codeblock}
Input parameters for a new {{site.data.keyword.cloud_notm}} IAM token Input parameters Values Header - `Content-Type: application/x-www-form-urlencoded`
- `Authorization: Basic Yng6Yng=`
Note:Yng6Yng=
equals the URL-encoded authorization for the user name bx and the password bx.
Body when using the refresh token - `grant_type: refresh_token`
- `response_type: cloud_iam uaa`
- `refresh_token:` Your {{site.data.keyword.cloud_notm}} IAM refresh token.
- `uaa_client_ID: cf`
- `uaa_client_secret:`
- `bss_account:` Your {{site.data.keyword.cloud_notm}} account ID.
uaa_client_secret
key with no value specified.Body when using the {{site.data.keyword.cloud_notm}} API key - `grant_type: urn:ibm:params:oauth:grant-type:apikey`
- `response_type: cloud_iam uaa`
- `apikey:` Your {{site.data.keyword.cloud_notm}} API key.
- `uaa_client_ID: cf`
- `uaa_client_secret:`
uaa_client_secret
key with no value specified.Example API output:
{ "access_token": "<iam_token>", "refresh_token": "<iam_refresh_token>", "uaa_token": "<uaa_token>", "uaa_refresh_token": "<uaa_refresh_token>", "token_type": "Bearer", "expires_in": 3600, "expiration": 1493747503 }
{: screen}
You can find your new {{site.data.keyword.cloud_notm}} IAM token in the access_token, and the refresh token in the refresh_token field of your API output.
-
Continue working with the {{site.data.keyword.containerlong_notm}} API documentation by using the token from the previous step.
Refreshing {{site.data.keyword.cloud_notm}} IAM access tokens and obtaining new refresh tokens with the CLI
{: #cs_cli_refresh}
When you start a new CLI session, or if 24 hours has expired in your current CLI session, you must set the context for your cluster by running ibmcloud ks cluster config --cluster <cluster_name>
. When you set the context for your cluster with this command, the kubeconfig
file for your Kubernetes cluster is downloaded. Additionally, an {{site.data.keyword.cloud_notm}} Identity and Access Management (IAM) ID token and a refresh token are issued to provide authentication.
{: shortdesc}
ID token: Every IAM ID token that is issued via the CLI expires after one hour. When the ID token expires, the refresh token is sent to the token provider to refresh the ID token. Your authentication is refreshed, and you can continue to run commands against your cluster.
Refresh token: Refresh tokens expire every 30 days. If the refresh token is expired, the ID token cannot be refreshed, and you are not able to continue running commands in the CLI. You can get a new refresh token by running ibmcloud ks cluster config --cluster <cluster_name>
. This command also refreshes your ID token.