如何使用 kubeadm 安装 Kubernetes?
Posted CSDN
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何使用 kubeadm 安装 Kubernetes?相关的知识,希望对你有一定的参考价值。
本文讲解如何使用 kubeadm 安装 kubernetes 1.15.2。
192.168.10.89 master
192.168.10.7 node1
192.168.10.8 node2
yum -y install docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://5pkmy13c.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
systemctl enable kubelet && systemctl start kubelet
kubeadm config images list
W0815 09:36:13.251611 44413 version.go:98] could not fetch a Kubernetes version from the internet: unable to get URL "https://dl.k8s.io/release/stable-1.txt": Get https://dl.k8s.io/release/stable-1.txt: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
W0815 09:36:13.251730 44413 version.go:99] falling back to the local client version: v1.15.2
k8s.gcr.io/kube-apiserver:v1.15.2
k8s.gcr.io/kube-controller-manager:v1.15.2
k8s.gcr.io/kube-scheduler:v1.15.2
k8s.gcr.io/kube-proxy:v1.15.2
k8s.gcr.io/pause:3.1
k8s.gcr.io/etcd:3.3.10
k8s.gcr.io/coredns:1.3.1
images=(
kube-apiserver:v1.15.2
kube-controller-manager:v1.15.2
kube-scheduler:v1.15.2
kube-proxy:v1.15.2
pause:3.1
etcd:3.3.10
coredns:1.3.1
)
for imageName in ${images[@]} ; do
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/$imageName
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/$imageName k8s.gcr.io/$imageName
docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/$imageName
done
kubeadm init --kubernetes-version=v1.15.2 --pod-network-cidr=10.244.0.0/16 --service-cidr=10.96.0.0/12
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
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.168.10.89:6443 --token linp38.sdzgoaw3jvrnr5yq
--discovery-token-ca-cert-hash sha256:c8c4d08806ec22851c0eaa4e41962576b19d372e92f638a88e89f166e2a2c4af
kubeadm join 192.168.10.89:6443 --token linp38.sdzgoaw3jvrnr5yq
--discovery-token-ca-cert-hash sha256:c8c4d08806ec22851c0eaa4e41962576b19d372e92f638a88e89f166e2a2c4af
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
# kubectl get pods --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system coredns-5c98db65d4-5jntb 0/1 Pending 0 2m15s
kube-system coredns-5c98db65d4-db2xj 0/1 Pending 0 2m15s
kube-system etcd-k8s-1.localdomain 1/1 Running 0 81s
kube-system kube-apiserver-k8s-1.localdomain 1/1 Running 0 99s
kube-system kube-controller-manager-k8s-1.localdomain 1/1 Running 0 86s
kube-system kube-flannel-ds-amd64-pc4kp 1/1 Running 0 32s
kube-system kube-proxy-6qwv6 1/1 Running 0 2m15s
kube-system kube-scheduler-k8s-1.localdomain 1/1 Running 0 77s
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/bc79dd1505b0c8681ece4de4c0d86c5cd2643275/Documentation/kube-flannel.yml
# kubectl get pods --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system coredns-5c98db65d4-5jntb 1/1 Running 0 26m
kube-system coredns-5c98db65d4-db2xj 1/1 Running 0 26m
kube-system etcd-k8s-1.localdomain 1/1 Running 0 25m
kube-system kube-apiserver-k8s-1.localdomain 1/1 Running 0 25m
kube-system kube-controller-manager-k8s-1.localdomain 1/1 Running 0 25m
kube-system kube-flannel-ds-amd64-9tscr 1/1 Running 0 16m
kube-system kube-flannel-ds-amd64-pc4kp 1/1 Running 0 24m
kube-system kube-flannel-ds-amd64-tts29 1/1 Running 0 17m
kube-system kube-proxy-64f8t 1/1 Running 0 16m
kube-system kube-proxy-6qwv6 1/1 Running 0 26m
kube-system kube-proxy-js7bb 1/1 Running 0 17m
kube-system kube-scheduler-k8s-1.localdomain 1/1 Running 0 25m
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
systemctl enable kubelet && systemctl start kubelet
images=(
kube-proxy:v1.15.2
pause:3.1
coredns:1.3.1
)
for imageName in ${images[@]} ; do
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/$imageName
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/$imageName k8s.gcr.io/$imageName
docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/$imageName
done
kubeadm join 10.168.0.2:6443 --token 00bwbx.uvnaa2ewjflwu1ry --discovery-token-ca-cert-hash sha256:00eb62a2a6020f94132e3fe1ab721349bbcd3e9b94da9654cfe15f2985ebd711
# kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s-1.localdomain Ready master 10m v1.15.2
k8s-2.localdomain Ready <none> 89s v1.15.2
k8s-3.localdomain Ready <none> 67s v1.15.2
The connection to the server localhost:8080 was refused - did you specify the right host or port?
# cat .kube/config
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUN5RENDQWJDZ0F3SUJBZ0lCQURBTkJna3Foa2lHOXcwQkFRc0ZBREFWTVJNd0VRWURWUVFERXdwcmRXSmwKY201bGRHVnpNQjRYRFRFNU1EZ3hOVEF5TWpneU1sb1hEVEk1TURneE1qQXlNamd5TWxvd0ZURVRNQkVHQTFVRQpBeE1LYTNWaVpYSnVaWFJsY3pDQ0FTSXdEUVlKS29aSWh2Y05BUUVCQlFBRGdnRVBBRENDQVFvQ2dnRUJBTXpMClQycDJWamsyOVB4elBjSk5wSHM1QWxsUVIxNy8zMWRUNXJSTytVSkVFVzI2UC9xc3ZZSWE3U01pYi9IamNON1gKM1JwelMrVzNqVXVQd29MMlRuUkREYkNsSldLdHJ2S1lud2hKTXVYdU5ZWVAzbFNrSFpJQ3hSVkFBaDB5Mzh1bwpjaW9CRGMyQTkzQldqQzBWc2QrdC9EbFJwL0RESGk0dzR1bjVRbVFlbnBhZk14TzJIazVQa2g2Sm9DaWZOamN3CkhadGxMNnZwZi9FMDJiQXh1eGkrV1IwQUxxMG44Z1p5M3huRk5lWHczM2wwOCtiVVJPVDFKbnFKaGh1bEJPdTcKSUI5VWZEeXc0VzhsbEZYRWRrdHhWL214ZWxQbFl6cXduTGN4eFVqUE80cmNBak5YZnFuY1M1UmFvNCt5TnV1NwpKbGR1RytXamRwaGZuRUVHQ2kwQ0F3RUFBYU1qTUNFd0RnWURWUjBQQVFIL0JBUURBZ0trTUE4R0ExVWRFd0VCCi93UUZNQU1CQWY4d0RRWUpLb1pJaHZjTkFRRUxCUUFEZ2dFQkFEdVl1ZTVDU3VkN1BZTzh1Zlh2a0k3Sk1VVzMKdnZjTDVDd3N5MXgwYWxxSUlxSXR4YS90UDRpbXhaQVJoTU1mVE85S3plcGpYd2VVelNTS1JoUWY4S2ZPUTJOeQpFaUJKMHp5VmprcmdUblFlT0xPQWE1TEFyNThBd1ZGWis1aFFNZk9SWENmZ004MVBNVC82NVovQUxQeXozWndICklTd0Noa3JTK2ZhUUhqWGh1M1ZoQ283VlNuU0E0dFF4eGx1Z3RiQWU3Nm1sSXJ0b3o2czd1aEFuN09FbWdYNUIKNjBIN1VGL2VsNzRwVVZjVGszN2haRTRRMWxzNXpDMUlCck04YmFEODQyWTA1SE1zRE5TZnhlR3Iyb0RQWWt6SwprQk9OMkZoOGptODlldXFic3NGckMxZ1BNSE5FaXc4RUltM056bkw1NmJ2MGtYViszQThZTWtKYUU4ST0KLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo=
server: https://192.168.10.89:6443
name: kubernetes
……
scp -r .kube/ node1:/root
scp -r .kube/ node2:/root
热 文 推 荐
点击阅读原文参与问卷,好礼送不停。
以上是关于如何使用 kubeadm 安装 Kubernetes?的主要内容,如果未能解决你的问题,请参考以下文章
【K8s 精选】CKA - 使用 Kubeadm 安装基本集群