Containerizing​ kubectl for working with OKE (Oracle Kubernetes Engine)


kubectl is one of the command line interfaces for managing k8s. In this post, we are containerizing kubectl for easy utilization across different environments.

Because kubectl in OKE is related with OCI CLI, we are setting up the kubectl tool by adding it to ocloudshell container we created in this post.

STEP 1

Configure OCI CLI as mentioned in the referenced post

STEP 2

Download kubectl and put it in the ocloudshell directory
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.12.0/bin/linux/amd64/kubectl

STEP 3

Configure kubectl for OKE following instructions you can find in the main page of each K8s cluster created in the OCI dashboard UI:

kubeconfig

STEP 4

Copy the .kube directory created in your home directory to the ocloudshell directory

STEP 5

Create Dockerfile

FROM store/oracle/serverjre:8
ENV LC_ALL=en_US.utf8 \
LANG=en_US.utf8
ARG OPC_CLI_VERSION=18.1.2
ENV OPC_CLI_PKG=opc-cli-$OPC_CLI_VERSION.zip
WORKDIR /ocloudshell/
RUN curl -o /etc/yum.repos.d/public-yum-ol7.repo http://yum.oracle.com/public-yum-ol7.repo \
&& yum-config-manager --enable ol7_developer_EPEL \
&& yum-config-manager --enable ol7_developer \
&& yum -y install unzip python-oci-cli \
&& rm -rf /var/cache/yum/*
WORKDIR /root
ADD .oci/ .oci/
RUN chmod 400 .oci/config
RUN chmod 400 .oci/oci_api_key.pem
ADD .kube/ .kube/
ADD kubectl /usr/local/bin/kubectl
RUN chmod +x /usr/local/bin/kubectl
CMD ["/bin/bash"]

STEP 6

Create and push the container to a private repo*
docker build -t yourrepo/ocloudshell .

docker push yourrepo/ocloudshell
(*) Remember, don’t push to public repo or you are putting in serious risk your environment!!

TEST IT

So far, so good. Let’s test the container executing a command, for instance:

docker run -it javiermugueta/ocloudshell kubectl get po

That’s all folks!

Enjoy 🙂

IT

javier mugueta View All →

Me and my circumstance

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: