Monday, February 11, 2019

How To Add OKE Worker Nodes via OCI API

Requirement

  We have Kubernetes cluster running in OKE (Oracle Kubernetes Engine).  We would like to dig deeper to use OCI API to manager the node pool of our K8S cluster. ie we can add a new worker node into our new private subnet. With OCI API, we can have more flexibility to handle worker nodes in the cluster.  In this example, we plan to use curl and raw REST API calls to do that.  Later oci-cli or SDK would support such functions

Solution

  • First to install oci-curl .  It is a Bash Shell script. Please refer OCI Doc
  • Configure the oci-curl to use correct tenancyId , authUserId , keyFingerprint, privateKeyPath. More details Please refer OCI Credential Doc and  OCI API  details
  • Test oci-curl . If you can get result like below , it means it works 
# .   ./oci-curl.sh
# oci-curl containerengine.us-ashburn-1.oraclecloud.com GET "/20180222/clusterOptions/all"
{
  "kubernetesVersions": [
    "v1.10.11",
    "v1.11.5"
  ]
  • Prepare oke-nodepool.json The example of json file is like
{
  "compartmentId": "INSERT_YOUR_COMPARTMENT_ID",
  "clusterId": "INSERT_YOUR_CLUSTER_ID",
  "name": "INSERT_YOUR_NODE_POOL_NAME",
  "kubernetesVersion": "INSERT_YOUR_K8S_VERSION",
  "nodeImageName": "INSERT_YOUR_CUSTOM_IMAGE_OCID",
  "nodeShape": "INSERT_YOUR_SHAPE_NAME",
  "nodeMetadata": {
    "INSERT_YOUR_CUSTOM_KEY_1": "INSERT_YOUR_CUSTOM_VALUE_1",
    "INSERT_YOUR_CUSTOM_KEY_2": "INSERT_YOUR_CUSTOM_VALUE_2"
  },
  "initialNodeLabels": [
    {
      "key": "node.info/INSERT_YOUR_SAMPLE_KEY",
      "value": "INSERT_YOUR_SAMPLE_VALUE"
    }
  ],
  "sshPublicKey": "INSERT_YOUR_SSH_PUBLIC_KEY",
  "quantityPerSubnet": INSERT_YOUR_QTY_PER_SUBNET,
  "subnetIds": [
    "",
    "",
    ""
  ]
}
  • Create a node pool 
oci-curl containerengine.us-ashburn-1.oraclecloud.com POST ./oke-nodepool.json "/20180222/nodePools"
  • Go to the OCI ashburn console , a new nodepool would be created in OKE according to json file.

No comments: