Kubernetes: Instalação Offline ou Instalação usando repositórios privados

From Wiki
Revision as of 20:41, 8 August 2019 by Ebasso (talk | contribs)

Trabalhei em uma empresa onde as regras de segurança bloqueava o acesso a sites/repositórios externos. Essa situação dificulta em muito a instalação do Docker e Kubernetes.

Neste artigo descrevo como driblei essa situação e consegui instalar o meu cluster Kubernetes.

Para Binários e RPMs

Docker - Opção 1 - Download dos arquivos e Instalação manual

Faça o download dos arquivos em uma estação que tenha acesso à Internet

wget -c https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-17.03.3.ce-1.el7.x86_64.rpm
wget -c https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-selinux-17.03.3.ce-1.el7.noarch.rpm
wget -c https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-18.06.3.ce-3.el7.x86_64.rpm
wget -c https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-18.09.6-3.el7.x86_64.rpm
wget -c https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-cli-18.09.6-3.el7.x86_64.rpm
wget -c https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.5-3.1.el7.x86_64.rpm

Copiar via scp para o servidor sem acesso a internet. E executar

yum -y install docker-ce-18.09.6-3.el7.x86_64.rpm docker-ce-cli-18.09.6-3.el7.x86_64.rpm

Docker - Opção 2 - Download dos arquivos e montagem de repositório

Faça o download dos arquivos em uma estação que tenha acesso à Internet

mkdir -p /tmp/docker-mirror/linux/centos/7/x86_64/stable/repodata/
mkdir -p /tmp/docker-mirror/linux/centos/7/x86_64/stable/Packages/

cd /tmp/docker-mirror/linux/centos
wget -c https://download.docker.com/linux/centos/gpg

cd /tmp/docker-mirror/linux/centos/7/x86_64/stable/repodata/
wget -c https://download.docker.com/linux/centos/7/x86_64/stable/repodata/repomd.xml
wget -c https://download.docker.com/linux/centos/7/x86_64/stable/repodata/27151177db68b47d024022599f6cdb8d0758feaefd8c65e43e8313af62eed131-filelists.xml.gz
wget -c https://download.docker.com/linux/centos/7/x86_64/stable/repodata/2811439ca3c66a6cb946abe2a8e4cfea7f364e09ca9ab0f4ba10f2333b74b911-filelists.sqlite.bz2
wget -c https://download.docker.com/linux/centos/7/x86_64/stable/repodata/65c4f66e2808d328890505c3c2f13bb35a96f457d1c21a6346191c4dc07e6080-updateinfo.xml.gz
wget -c https://download.docker.com/linux/centos/7/x86_64/stable/repodata/83a7f2e6c4dffb21fe0cc818e572bb4bf2bbb8dbd860dad66179a8bbc06f64d9-other.xml.gz
wget -c https://download.docker.com/linux/centos/7/x86_64/stable/repodata/b292d47325588b6eb4f589e04bbf0f95727fa1755d8fa65d6978e1294f11b167-primary.sqlite.bz2
wget -c https://download.docker.com/linux/centos/7/x86_64/stable/repodata/c2d756b11328eaa080323355c4b1c1d9442bbe8798b183b79fa53841274f1633-other.sqlite.bz2
wget -c https://download.docker.com/linux/centos/7/x86_64/stable/repodata/ff7792a80a96a8fd9eb9843f830bf7ffc031e67eef965d918f724f250b9e38bc-primary.xml.gz

cd /tmp/docker-mirror/linux/centos/7/x86_64/stable/Packages/
wget -c https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-17.03.3.ce-1.el7.x86_64.rpm
wget -c https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-selinux-17.03.3.ce-1.el7.noarch.rpm
wget -c https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-18.06.3.ce-3.el7.x86_64.rpm
wget -c https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-18.09.6-3.el7.x86_64.rpm
wget -c https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-cli-18.09.6-3.el7.x86_64.rpm
wget -c https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.5-3.1.el7.x86_64.rpm

Copiar via scp para o servidor http interno, a url que iremos utilizar será

http://repomirror.company.com/docker-mirror

Na máquina de destino basta usar

Criar arquivo /etc/yum.repos.d/docker-ce.repo, com o conteúdo:


[docker-ce]
name=Docker CE Stable - $basearch
#baseurl=https://download.docker.com/linux/centos/7/$basearch/stable
baseurl=http://repomirror.company.com/docker-mirror/linux/centos/7/$basearch/stable/
enabled=1
gpgcheck=1
#gpgkey=https://download.docker.com/linux/centos/gpg
gpgkey=http://repomirror.company.com/docker-mirror/linux/centos/gpg
 

Instalando os pacotes no CentOS

yum install -y docker-ce-18.06

Kubernetes - Opção 1 - Download dos arquivos e Instalação manual

Faça o download dos arquivos em uma estação que tenha acesso à Internet

wget -c https://packages.cloud.google.com/yum/pool/542cbe1b886808a7f025595b2bfe776fd08de5d2dab0a80f22947cf400b89a2c-kubectl-1.11.9-0.x86_64.rpm -O kubectl-1.11.9-0.x86_64.rpm
wget -c https://packages.cloud.google.com/yum/pool/2d3fea397e599d94ec3d67582c522719ca3e9bd946c0f89a33caa07a49e1b883-kubeadm-1.11.9-0.x86_64.rpm -O kubeadm-1.11.9-0.x86_64.rpm
wget -c https://packages.cloud.google.com/yum/pool/b82b358f2951dc396af6e2e56f9b1ca6ab5b494208996a5788682d9e49312d7b-kubelet-1.11.9-0.x86_64.rpm -O kubelet-1.11.9-0.x86_64.rpm

Copiar via scp para o servidor sem acesso a internet. E executar

yum -y install docker-ce-18.09.6-3.el7.x86_64.rpm docker-ce-cli-18.09.6-3.el7.x86_64.rpm

Kubernetes - Opção 2 - Download dos arquivos e montagem de repositório

Faça o download dos arquivos em uma estação que tenha acesso à Internet

mkdir -p /tmp/kubernetes-mirror/yum/repos/kubernetes-el7-x86_64/repodata/
mkdir -p /tmp/kubernetes-mirror/yum/pool
mkdir -p /tmp/kubernetes-mirror/yum/doc

cd /tmp/kubernetes-mirror/yum/doc
wget -c https://packages.cloud.google.com/yum/doc/yum-key.gpg 
wget -c https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg

cd /tmp/kubernetes-mirror/yum/repos/kubernetes-el7-x86_64/repodata/
wget -c https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64/repodata/filelists.xml
wget -c https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64/repodata/filelists.xml.gz
wget -c https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64/repodata/other.xml
wget -c https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64/repodata/other.xml.gz
wget -c https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64/repodata/primary.xml
wget -c https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64/repodata/primary.xml.gz
wget -c https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64/repodata/repomd.xml
wget -c https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64/repodata/repomd.xml.gz

cd /tmp/kubernetes-mirror/yum/pool
wget -c https://packages.cloud.google.com/yum/pool/542cbe1b886808a7f025595b2bfe776fd08de5d2dab0a80f22947cf400b89a2c-kubectl-1.11.9-0.x86_64.rpm
wget -c https://packages.cloud.google.com/yum/pool/2d3fea397e599d94ec3d67582c522719ca3e9bd946c0f89a33caa07a49e1b883-kubeadm-1.11.9-0.x86_64.rpm
wget -c https://packages.cloud.google.com/yum/pool/b82b358f2951dc396af6e2e56f9b1ca6ab5b494208996a5788682d9e49312d7b-kubelet-1.11.9-0.x86_64.rpm

Copiar via scp para o servidor http interno, a url que iremos utilizar será

http://repomirror.company.com/kubernetes-mirror

Na máquina de destino basta usar

Criar arquivo /etc/yum.repos.d/kubernetes.repo, com o conteúdo:

[kubernetes]
name=Kubernetes
#baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
baseurl=https://repomirror.company.com/kubernetes-mirror/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
#gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
gpgkey=https://repomirror.company.com/kubernetes-mirror/yum/doc/yum-key.gpg https://repomirror.company.com/kubernetes-mirror/yum/doc/rpm-package-key.gpg
exclude=kube*

Instalando os pacotes no CentOS

yum install -y kubelet-1.11.9 kubeadm-1.11.9 kubectl-1.11.9

cfssl mirror

Download dos arquivos

mkdir -p /tmp/cfssl-mirror/R1.2
cd /tmp/cfssl-mirror/R1.2
wget -c http://pkg.cfssl.org/R1.2/cfssl_linux-amd64
wget -c http://pkg.cfssl.org/R1.2/cfssljson_linux-amd64
wget -c http://pkg.cfssl.org/R1.2/cfssl-certinfo_linux-amd64
cd ../..

Copiar para o servidor http interno. E utilizar

wget -c http://<servidor_interno>/cfssl-mirror/R1.2/cfssl_linux-amd64
wget -c http://<servidor_interno>/cfssl-mirror/R1.2/cfssljson_linux-amd64
wget -c http://<servidor_interno>/cfssl-mirror/R1.2/cfssl-certinfo_linux-amd64

Etcd mirror

Download dos arquivos

mkdir -p /tmp/etcd-mirror/etc/v3.1.13
cd /tmp/etcd-mirror/etc/v3.1.13
wget -c https://storage.googleapis.com/etcd/v3.1.13/etcd-v3.1.13-linux-amd64.tar.gz
cd ../..

Copiar para o servidor http interno. E utilizar

wget -c http://<servidor_interno>/cfssl-mirror/R1.2/cfssl_linux-amd64
wget -c http://<servidor_interno>/cfssl-mirror/R1.2/cfssljson_linux-amd64
wget -c http://<servidor_interno>/cfssl-mirror/R1.2/cfssl-certinfo_linux-amd64

Para Docker Images

Faça o pull das imagens em uma estação que tenha acesso à Internet

docker pull gcr.io/google_containers/kube-apiserver-amd64:v1.9.6
docker pull gcr.io/google_containers/kube-scheduler-amd64:v1.9.6
docker pull gcr.io/google_containers/kube-controller-manager-amd64:v1.9.6
docker pull gcr.io/google_containers/kube-proxy-amd64:v1.9.6
docker pull gcr.io/google_containers/heapster-amd64:v1.5.1
docker pull gcr.io/google_containers/k8s-dns-kube-dns-amd64:1.14.8
docker pull gcr.io/google_containers/k8s-dns-dnsmasq-nanny-amd64:1.14.8
docker pull gcr.io/google_containers/k8s-dns-sidecar-amd64:1.14.8
docker pull gcr.io/google_containers/pause-amd64:3.0
docker pull jasonbrooks/flannel
docker pull haproxy

Salve as imagens como .tar

docker save gcr.io/google_containers/kube-apiserver-amd64:v1.9.6 -o kube-apiserver-amd64_v1.9.6.tar docker save gcr.io/google_containers/kube-scheduler-amd64:v1.9.6 -o kube-scheduler-amd64_v1.9.6.tar docker save gcr.io/google_containers/kube-controller-manager-amd64:v1.9.6 -o kube-controller-manager-amd64_v1.9.6.tar docker save gcr.io/google_containers/kube-proxy-amd64:v1.9.6 -o kube-proxy-amd64_v1.9.6.tar docker save gcr.io/google_containers/heapster-amd64:v1.5.1 -o heapster-amd64_v1.5.1.tar docker save gcr.io/google_containers/k8s-dns-kube-dns-amd64:1.14.8 -o k8s-dns-kube-dns-amd64_1.14.8.tar docker save gcr.io/google_containers/k8s-dns-dnsmasq-nanny-amd64:1.14.8 -o k8s-dns-dnsmasq-nanny-amd64_1.14.8.tar docker save gcr.io/google_containers/k8s-dns-sidecar-amd64:1.14.8 -o k8s-dns-sidecar-amd64_1.14.8.tar docker save gcr.io/google_containers/pause-amd64:3.0 -o pause-amd64_3.0.tar docker save jasonbrooks/flannel:lastest -o flannel_lastest.tar docker save haproxy -o haproxy_lastest.tar

Copiar via scp para o servidor com docker, e executar o load das imagens provenientes de arquivos tar.

docker load -i kube-apiserver-amd64_v1.9.6.tar docker load -i kube-scheduler-amd64_v1.9.6.tar docker load -i kube-controller-manager-amd64_v1.9.6.tar docker load -i kube-proxy-amd64_v1.9.6.tar docker load -i heapster-amd64_v1.5.1.tar docker load -i k8s-dns-kube-dns-amd64_1.14.8.tar docker load -i k8s-dns-dnsmasq-nanny-amd64_1.14.8.tar docker load -i k8s-dns-sidecar-amd64_1.14.8.tar docker load -i pause-amd64_3.0.tar docker load -i flannel_lastest.tar docker load -i haproxy_lastest.tar

Ver também