SoFunction
Updated on 2025-03-10

Detailed process of installing kubectl and deploying kube-apiserver in centos system

1. Install using yum (recommended)

Add Kubernetes software source:
First, you need to add the official YUM software source for Kubernetes. This can be done by downloading and installing files.

cat <<EOF | sudo tee /etc//
[kubernetes]
name=Kubernetes
baseurl=/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=/yum/doc/ /yum/doc/
EOF

Install kubectl:
Use yum to install kubectl.

sudo yum install -y kubectl

Verify installation:
Verify that kubectl is installed correctly and check the version.

kubectl version --client

2. Use curl and tar to install

Download kubectl:
Use curl to download the latest version of kubectl.

curl -LO "https://dl./release/$(curl -L -s https://dl./release/)/bin/linux/amd64/kubectl"

Add execution permissions:
Add execution permissions to the downloaded kubectl file.

chmod +x ./kubectl

Move to /usr/local/bin:
Move kubectl to the /usr/local/bin directory to make it available globally.

sudo mv ./kubectl /usr/local/bin/kubectl

Verify installation:
Verify that kubectl is installed correctly and check the version.

kubectl version --client

Deploy kube-apiserver

Install kube-apiserver
First, you need to get the binary file of Kubernetes. You can download the required version from the GitHub repository in Kubernetes. The following command shows how to download and unzip the binaries of Kubernetes version 1.29.4:

wget /kubernetes/kubernetes/archive/v1.29.
tar -zxvf v1.29.
cd kubernetes-1.29.4

Then, copy the kube-apiserver to the /usr/local/bin directory:

sudo cp _output/bin/kube-apiserver /usr/local/bin/
  • Prepare the configuration file for kube-apiserver

Create the configuration file for kube-apiserver /etc/kubernetes/manifests/:

cat &lt;&lt;EOF | sudo tee /etc/kubernetes/manifests/
apiVersion: v1
kind: Pod
metadata:
  name: kube-apiserver
  namespace: kube-system
spec:
  hostNetwork: true
  containers:
  - name: kube-apiserver
    image: /kube-apiserver:v1.29.4
    command:
    - kube-apiserver
    - --advertise-address=&lt;MASTER_IP&gt; # Replace the IP address of the Master node    - --allow-privileged=true
    - --apiserver-count=3
    - --authorization-mode=Node,RBAC
    - --client-ca-file=/etc/kubernetes/ssl/
    - --etcd-cafile=/etc/kubernetes/ssl/
    - --etcd-certfile=/etc/kubernetes/ssl/
    - --etcd-keyfile=/etc/kubernetes/ssl/
    - --etcd-servers=https://&lt;ETCD_IP&gt;:2379 # Replace with the address of the etcd server    - --insecure-bind-address=0.0.0.0
    - --kubelet-client-certificate=/etc/kubernetes/ssl/
    - --kubelet-client-key=/etc/kubernetes/ssl/
    - --kubelet-https=true
    - --service-account-key-file=/etc/kubernetes/ssl/
    - --service-cluster-ip-range=10.254.0.0/16
    - --tls-cert-file=/etc/kubernetes/ssl/
    - --tls-private-key-file=/etc/kubernetes/ssl/
    - --service-node-port-range=30000-50000
    - --audit-log-path=/var/log/kube-audit/
    - --audit-log-maxage=30
    - --audit-log-maxbackup=3
    - --audit-log-maxsize=100
    - --v=2
EOF

Make sure to replace <MASTER_IP> and <ETCD_IP> with your actual IP address.

  • Create a kube-apiserver service

Create the systemd service file for kube-apiserver:

sudo vim /usr/lib/systemd/system/

Add the following:

[Unit]
Description=Kubernetes API Server
Documentation=/kubernetes/kubernetes
[Service]
EnvironmentFile=/etc/kubernetes/config/
ExecStart=/usr/local/bin/kube-apiserver $KUBE_APISERVER_OPTS
Restart=on-failure
[Install]
WantedBy=
  • Start the kube-apiserver service
sudo systemctl daemon-reload
sudo systemctl enable kube-apiserver
sudo systemctl start kube-apiserver
  • Verify that kube-apiserver is running
sudo systemctl status kube-apiserver

This is the article about how to install kubectl and deploy kube-apiserver in the centos system. For more related content on installing kubectl and deploying kube-apiserver, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!