The software described in this documentation is either no longer supported or is in extended support.
Oracle recommends that you upgrade to a current supported release.

2.2.2 Setting up the kubectl Command on the Operator Node

Oracle Linux Cloud Native Environment allows you to create multiple environments from the operator node. With this in mind, it is recommended that you use the kubectl command on a master node in the Kubernetes cluster. If you use the kubectl command from the operator node, and you have multiple environments deployed, you may inadvertently manage an unexpected Kubernetes cluster. If you do want to set up the kubectl command to run it the operator node, you need to configure it.

The kubectl command is not set up by default to connect to Kubernetes from the operator node. To set up the kubectl command on the operator node, create a local copy of the Kubernetes configuration file, and use that to connect to the cluster.

To use the kubectl command as a regular user, perform the following steps on the operator node.

To setup kubectl on an operator node:

  1. Get the Kubernetes configuration and copy it to a local file on the operator node. Use the olcnectl module property get command to get the Kubernetes configuration from the kubecfg property of the kubernetes module. For example:

    $ olcnectl --api-server 127.0.0.1:8091 module property get \
      --environment-name myenvironment --name mycluster \
      --property kubecfg | base64 -d > kubeconfig.yaml
  2. You can use the kubeconfig.yaml file directly when running kubectl commands using the --kubeconfig option. For example:

    $ kubectl get pods -n kube-system --kubeconfig kubeconfig.yaml
  3. You can also save the Kubernetes configuration so you do not need to use the --kubeconfig option. Create the .kube subdirectory in your home directory:

    $ mkdir -p $HOME/.kube
  4. Copy the Kubernetes kubeconfig.yaml file to the .kube directory:

    $ cp kubeconfig.yaml $HOME/.kube/config
  5. Export the path to the file for the KUBECONFIG environment variable:

    $ export KUBECONFIG=$HOME/.kube/config

    To permanently set this environment variable, add it to your .bashrc file.

    $ echo 'export KUBECONFIG=$HOME/.kube/config' >> $HOME/.bashrc
  6. Verify that you can use the kubectl command.

    Kubernetes runs many of its services to manage the cluster configuration as containers running as Kubernetes pods, which can be viewed by running the following command on a master node:

    $ kubectl get pods -n kube-system
    NAME                                    READY   STATUS    RESTARTS   AGE
    coredns-5bc65d7f4b-qzfcc                1/1     Running   0          23h
    coredns-5bc65d7f4b-z64f2                1/1     Running   0          23h
    etcd-master1.example.com                1/1     Running   0          23h
    kube-apiserver-master1.example.com      1/1     Running   0          23h
    kube-controller-master1.example.com     1/1     Running   0          23h
    kube-flannel-ds-2sjbx                   1/1     Running   0          23h
    kube-flannel-ds-njg9r                   1/1     Running   0          23h
    kube-proxy-m2rt2                        1/1     Running   0          23h
    kube-proxy-tbkxd                        1/1     Running   0          23h
    kube-scheduler-master1.example.com      1/1     Running   0          23h
    kubernetes-dashboard-7646bf6898-d6x2m   1/1     Running   0          23h