Skip to content

Instantly share code, notes, and snippets.

@isennkubilay
Last active June 20, 2024 09:20
Show Gist options
  • Save isennkubilay/0d1a4efee33b54a73223a0cb89cb1eb2 to your computer and use it in GitHub Desktop.
Save isennkubilay/0d1a4efee33b54a73223a0cb89cb1eb2 to your computer and use it in GitHub Desktop.
Kubernetes offline installing

KUBERNETES OFFLINE INSTALLING

1- Docker Download

yum install -y epel-release

yum install -y yum-utils

yum-config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo

yum makecache fast

mkdir docker

cd docker

yumdownloader --resolve docker-ce

tar cvfz docker.tar ./*

2- DOCKER'I OFFLINE MACHINE INSTALL

mkdir docker

cd docker

tar xvf docker.tar .

rpm -ivh --replacefiles --replacepkgs *.rpm

rpm -iv *.rpm

systemctl start docker && systemctl enable docker

3- KUBERNETES DOWNLOAD FROM INTERNET MACHINE

mkdir kubernetes

cd kubernetes

cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=0
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF

yum makecache fast

yumdownloader --resolve kubelet kubeadm kubectl

tar cvfz kubernetes.tar ./*

4- GET KUBERNETES IMAGES

docker save k8s.gcr.io/kube-apiserver:v1.23.5 > ./kube-apiserver_v1.23.5.tar

docker save k8s.gcr.io/kube-proxy:v1.23.5 > ./kube-proxy_v1.23.5.tar

docker save k8s.gcr.io/kube-scheduler:v1.23.5 > ./kube-scheduler_v1.23.5.tar

docker save k8s.gcr.io/kube-controller-manager:v1.23.5 > ./kube-controller-manager_v1.23.5.tar

docker save k8s.gcr.io/etcd:3.5.1-0 > ./etcd_3.5.1-0.tar

docker save k8s.gcr.io/coredns/coredns:v1.8.6 > ./coredns_v1.8.6.tar

docker save k8s.gcr.io/pause:3.6 > ./pause_3.6.tar

--- THIS IMAGE WILL BE IN KUBERNETES MACHINE

WEAVENET IMAGES

docker pull weaveworks/weave-kube:2.8.1

docker pull weaveworks/weave-npc:2.8.1

docker save weaveworks/weave-kube:2.8.1 > ./weave-kube_2.8.1.tar

docker save weaveworks/weave-npc:2.8.1 > ./weave-npc_2.8.1.tar

-----THIS IMAGES WILL BE MASTER MACHINE

7- INSTALLING KUBERNETES

systemctl enable kubelet

systemctl start kubelet

cat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF

sysctl --system

sudo setenforce 0

sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config

sed -e '/swap/s/^/#/g' -i /etc/fstab

sudo swapoff -a

cat > /etc/docker/daemon.json << EOF
 { 
 "exec-opts": ["native.cgroupdriver=systemd"],
 "insecure-registries" : [ "hostname.cloudapp.net:5000" ],
 "log-driver": "json-file",
 "log-opts": {
 "max-size": "100m"
 },
 "storage-driver": "overlay2",
 "storage-opts": [
 "overlay2.override_kernel_check=true"
 ]
 }
EOF

kubeadm init --image-repository=local.docker.registry:5000

Your Kubernetes control-plane has initialized successfully!

To start using your cluster, you need to run the following as a regular user:

mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config

Alternatively, if you are the root user, you can run:

export KUBECONFIG=/etc/kubernetes/admin.conf

You should now deploy a pod network to the cluster. Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at: https://kubernetes.io/docs/concepts/cluster-administration/addons/

Then you can join any number of worker nodes by running the following on each as root:

kubeadm join 192.1.1.10:6443 --token qctygg.9udos4psu2cbhvcp \ --discovery-token-ca-cert-hash sha256:ed71bdba6ed54d95e77bd6cb55daaa88cc8225e02e21ce6792b3a2ad5ee97534

#!/bin/bash
# Set Kubernetes version
KUBERNETES_VERSION="1.22.0-00"
# Set download directories
DOWNLOAD_DIR_KUBERNETES="/path/to/download/kubernetes"
DOWNLOAD_DIR_DOCKER="/path/to/download/docker"
# Create directories if they don't exist
mkdir -p "${DOWNLOAD_DIR_KUBERNETES}"
mkdir -p "${DOWNLOAD_DIR_DOCKER}"
# Add Kubernetes signing key
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
# Add Kubernetes repository
sudo tee /etc/apt/sources.list.d/kubernetes.list <<EOF
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF
# Add Docker repository and signing key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
# Update package listings
sudo apt-get update
# Download Kubernetes packages
sudo apt-get install --download-only -y kubelet=${KUBERNETES_VERSION} kubeadm=${KUBERNETES_VERSION} kubectl=${KUBERNETES_VERSION}
sudo cp /var/cache/apt/archives/*.deb "${DOWNLOAD_DIR_KUBERNETES}"
# Download Docker packages
sudo apt-get install --download-only -y docker-ce docker-ce-cli containerd.io
sudo cp /var/cache/apt/archives/*.deb "${DOWNLOAD_DIR_DOCKER}"
# Output the paths to the downloaded packages
echo "Kubernetes packages downloaded to: ${DOWNLOAD_DIR_KUBERNETES}"
echo "Docker packages downloaded to: ${DOWNLOAD_DIR_DOCKER}"
#!/bin/bash
# Define the directory where you have the Kubernetes installation packages
PACKAGE_DIR="/path/to/kubernetes/packages"
# Disable swap - required for Kubernetes
swapoff -a
sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
# Load necessary kernel modules
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
overlay
br_netfilter
EOF
modprobe overlay
modprobe br_netfilter
# Set up required sysctl params
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system
# Install Docker from local package archives
dpkg -i $PACKAGE_DIR/docker/*.deb
# Add Kubernetes packages to the local dpkg database
dpkg -i $PACKAGE_DIR/kubernetes/*.deb
# Hold the Kubernetes packages to prevent unintended upgrades
apt-mark hold kubelet kubeadm kubectl
# Initialize the Kubernetes cluster using kubeadm
kubeadm init --pod-network-cidr=10.244.0.0/16
# To start using your cluster, you need to run the following as a regular user
mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config
# Install a pod network. Here we install Flannel, but you can choose others.
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
# To allow workloads to be scheduled to the master node (optional)
kubectl taint nodes --all node-role.kubernetes.io/master-
# Verify the installation
kubectl get nodes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment