k8s-集群搭建的三种方式和区别,kubeadm、minikube,二进制包,镜像
https://blog.csdn.net/qq_21187515/article/details/101460039
1、用阿里云镜像
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
2.安装 kubectl
参考:https://kubernetes.io/zh/docs/tasks/tools/install-kubectl/
使用本地包安装:
yum install -y kubectl
或
去 https://github.com/kubernetes/kubernetes/find/master 找CHANGELOG/CHANGELOG-1.xx.md
wget https://dl.k8s.io/v1.9.3/kubernetes-client-linux-amd64.tar.gz
tar -zxvf kubernetes-client-linux-amd64.tar.gz
cd kubernetes/client/bin
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
3、运行 kubectl version,返回版本信息(有即可,其他报错忽略),说明安装成功
4、k8s中shell的自动补全
yum install bash-completion -y
echo "source <(kubectl completion bash)" >> ~/.bashrc
5、配置kubectl
参考:https://kubernetes.io/docs/tasks/access-application-cluster/configure-access-multiple-clusters/
Minikube 是一个轻量级的 Kubernetes 实现,会在本机创建一台虚拟机,并部署一个只包含一个节点的简单集群
6、提示缺少minikubectl,安装minkubectl
参考:https://yq.aliyun.com/articles/221687
curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 \
&& chmod +x minikube
如果直接下载不了,就去github下载,下载地址:https://github.com/kubernetes/minikube/releases/tag/v1.11.0
yum install conntrack
minikube start --image-mirror-country="cn" --image-repository="registry.cn-hangzhou.aliyuncs.com/google_containers" --driver=no
minikube status
minikube start --xx,有很多可选参数配置
防火墙开放端口
[root@localhost openssh]# firewall-cmd --list-ports
[root@localhost openssh]# firewall-cmd --zone=public --add-port=3338/tcp --permanent
success
[root@localhost openssh]# firewall-cmd --zone=public --add-port=23/tcp --permanent
success
[root@localhost openssh]# firewall-cmd --list-ports
[root@localhost openssh]# firewall-cmd --reload
success
[root@localhost openssh]# firewall-cmd --list-ports
docker pull mirrorgooglecontainers/kube-apiserver-amd64:v1.12.2
docker pull mirrorgooglecontainers/kube-controller-amd64:v1.12.2
docker pull mirrorgooglecontainers/kube-controller-manager-amd64:v1.12.2
docker pull mirrorgooglecontainers/kube-scheduler-amd64:v1.12.2
docker pull mirrorgooglecontainers/kube-proxy-amd64:v1.12.2
docker pull mirrorgooglecontainers/pause:3.1
docker pull mirrorgooglecontainers/etcd-amd64:3.2.24
docker pull mirrorgooglecontainers/coredns:1.2.2
docker pull mirrorgooglecontainers/coredns-amd64:1.2.2
docker pull coredns/coredns:1.2.2
改tag名
docker tag mirrorgooglecontainers/kube-proxy-amd64:v1.12.2 k8s.gcr.io/kube-proxy:v1.12.2
docker tag mirrorgooglecontainers/kube-apiserver-amd64:v1.12.2 k8s.gcr.io/kube-apiserver:v1.12.2
docker tag mirrorgooglecontainers/kube-controller-manager-amd64:v1.12.2 k8s.gcr.io/kube-controller-manager:v1.12.2
docker tag mirrorgooglecontainers/kube-scheduler-amd64:v1.12.2 k8s.gcr.io/kube-scheduler:v1.12.2
docker tag mirrorgooglecontainers/etcd-amd64:3.2.24 k8s.gcr.io/etcd:3.2.24
docker tag coredns/coredns:1.2.2 k8s.gcr.io/coredns:1.2.2
docker tag mirrorgooglecontainers/pause:3.1 k8s.gcr.io/pause:3.1
7.k8s使用测试
https://kubernetes.io/zh/docs/setup/learning-environment/minikube/
查看状态
kubectl get pod
报错查看:
kubectl describe pod
镜像拉取失败,替换镜像
docker pull cilium/echoserver
docker tag cilium/echoserver:latest k8s.gcr.io/echoserver:1.10
# 显式设置拉取策略为 IfNotPresent
$ kubectl run hello-minikube --image-pull-policy=IfNotPresent