Docker builds kubectl image implementation steps

Docker builds kubectl image implementation steps

If the program service is deployed using k8s integrated with gitlab ci/cd, the kubeclt image is needed in the gitlab-ci process. There are two ways to build a kubectl image using docker

Method 1 (the image is relatively small, about 45.8M)

Install the kubectl executable using curl on Linux

cd /usr/local/bin
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.20.1/bin/linux/amd64/kubectl
chmod +x ./kubectl

Refer to the official installation documentation for details

Next, create a new Dockerfile file in the /usr/local/bin directory and write the following content

FROM alpine:latest
COPY kubectl /usr/local/bin/
RUN chmod +x /usr/local/bin/kubectl

After the Dockerfile file is built, execute the build command in the same directory

docker build -t registry.cn-hangzhou.aliyuncs.com/sanchar/kubectl:v1.20.1 .

Wait for the image to be built

Method 2 (the image is relatively large, about 48.9M)

This method is relatively convenient, but the construction is slow. During the construction process, you need to download the kubectl executable file and directly create a new Dockerfile file with the following content

FROM alpine:latest

RUN apk add --update -t ​​deps curl

RUN curl -L https://storage.googleapis.com/kubernetes-release/release/v1.20.1/bin/linux/amd64/kubectl -o /usr/local/bin/kubectl \
  && chmod +x /usr/local/bin/kubectl

RUN apk del --purge deps \
  && rm /var/cache/apk/*

Execute the build command in the same directory

docker build -t registry.cn-hangzhou.aliyuncs.com/sanchar/kubectl:v1.20.1 .

at last

1. Test whether the built image can be used normally

docker run -it registry.cn-hangzhou.aliyuncs.com/sanchar/kubectl:v1.20.1 kubectl version --client

The output content is as follows, that is, the built image can be used normally

Client Version: version.Info{Major:"1", Minor:"20", GitVersion:"v1.20.1", GitCommit:"c4d752765b3bbac2237bf87cf0b1c2e307844666", GitTreeState:"clean", BuildDate:"2020-12-18T12:09:25Z", GoVersion:"go1.15.5", Compiler:"gc", Platform:"linux/amd64"}

2. Pull the image from the Registry

docker pull registry.cn-hangzhou.aliyuncs.com/sanchar/kubectl:v1.20.1

3. Push the image to the Registry and replace [ImageId] with the corresponding image ID

docker login --username=usernameregistry.cn-hangzhou.aliyuncs.com

docker tag [ImageId] registry.cn-hangzhou.aliyuncs.com/sanchar/kubectl:v1.20.1

docker push registry.cn-hangzhou.aliyuncs.com/sanchar/kubectl:v1.20.1

This is the end of this article about the implementation steps of Docker building kubectl image. For more relevant content about Docker building kubectl image, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • How to add automatic completion commands for docker and kubectl on Mac

<<:  Five ways to traverse objects in javascript Example code

>>:  Research on the value of position attribute in CSS (summary)

Recommend

CentOS8 installation tutorial of jdk8 / java8 (recommended)

Preface At first, I wanted to use wget to downloa...

Detailed tutorial on installing Ubuntu 19.10 on Raspberry Pi 4

Because some dependencies of opencv could not be ...

Steps for Docker to build its own local image repository

1. Environment and preparation 1. Ubuntu 14.04 2....

How to implement controllable dotted line with CSS

Preface Using css to generate dotted lines is a p...

Detailed example of jQuery's chain programming style

The implementation principle of chain programming...

Introduction to using MySQL commands to create, delete, and query indexes

MySQL database tables can create, view, rebuild a...

Vue.js performance optimization N tips (worth collecting)

Table of contents Functionalcomponents Childcompo...

Detailed explanation of transaction isolation levels in MySql study notes

background When we talk about transactions, every...

Research on the effect of page sidebar realized by JS

Table of contents Discover: Application of displa...

MySQL parameter related concepts and query change methods

Preface: In some previous articles, we often see ...

Linux MySQL root password forgotten solution

When using the MySQL database, if you have not lo...

How to print highlighted code in nodejs console

Preface When the code runs and an error occurs, w...

How to get form data in Vue

Table of contents need Get data and submit Templa...

Detailed steps for installing rockerChat in docker and setting up a chat room

Comprehensive Documentation github address https:...

A brief analysis of the use of watchEffect in Vue3

Preface Everyone should be familiar with the watc...