kubectl
Minikube
kind
kubeadm

虚拟机要保证2cpu、3g以上


sudo apt-get update && sudo apt-get install -y apt-transport-https gnupg2 curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update
sudo apt-get install -y kubectl
查看版本

ubuntu@k8s-master:~$ kubectl version --client
Client Version: version.Info{Major:"1", Minor:"20", GitVersion:"v1.20.2", GitCommit:"faecb196815e248d3ecfb03c680a4507229c2a56", GitTreeState:"clean", BuildDate:"2021-01-13T13:28:09Z", GoVersion:"go1.15.5", Compiler:"gc", Platform:"linux/amd64"}

查看配置信息

ubuntu@k8s-master:~$ kubectl cluster-info dump
W0202 21:53:28.638417    4099 loader.go:223] Config not found: /etc/kubernetes/admin.conf
The connection to the server localhost:8080 was refused - did you specify the right host or port?

则需要首先安装 minikube 等工具,然后重新运行上述命令

安装脚本

 curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
 sudo install minikube-linux-amd64 /usr/local/bin/minikube

ubuntu@k8s-master:~$ minikube start
😄  Ubuntu 20.04 上的 minikube v1.17.1
    ▪ KUBECONFIG=/etc/kubernetes/admin.conf
👎  Unable to pick a default driver. Here is what was considered, in preference order:
    ▪ virtualbox: Not installed: unable to find VBoxManage in $PATH
    ▪ vmware: Not installed: exec: "docker-machine-driver-vmware": executable file not found in $PATH
    ▪ docker: Not healthy: "docker version --format {{.Server.Os}}-{{.Server.Version}}" exit status 1: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.24/version: dial unix /var/run/docker.sock: connect: permission denied
    ▪ kvm2: Not installed: exec: "virsh": executable file not found in $PATH
    ▪ none: Not installed: running the 'none' driver as a regular user requires sudo permissions
    ▪ podman: Not installed: exec: "podman": executable file not found in $PATH

❌  Exiting due to DRV_NOT_DETECTED: No possible driver was detected. Try specifying --driver, or see https://minikube.sigs.k8s.io/docs/start/

ubuntu@k8s-master:~$ 

#使用 
#切换到非root用户
minikube start --vm-driver=docker # 启动
#he requested memory allocation of 2200MiB does not leave room for system overhead (total system memory: 2963MiB). You may face stability issues
minikube start --driver=docker --memory=2200mb
# 报The "docker" driver should not be used with root privileges 时#执行以下命令
sudo usermod -aG docker $USER && newgrp docker
#报错 failed to download gcr.io/k8s-minikube/kicbase:v0.0.10@sha256 可以用
minikube start --vm-driver=docker --base-image="anjone/kicbase" --image-mirror-country='cn' --image-repository='registry.cn-hangzhou.aliyuncs.com/google_containers'   --memory=2200mb

ubuntu@k8s-master:~$ minikube start --vm-driver=docker --base-image="anjone/kicbase"  --memory=2200mb
😄  Ubuntu 20.04 上的 minikube v1.17.1
✨  根据现有的配置文件使用 docker 驱动程序

🧯  The requested memory allocation of 2200MiB does not leave room for system overhead (total system memory: 2963MiB). You may face stability issues.
💡  建议:Start minikube with less memory allocated: 'minikube start --memory=2200mb'


🧯  The requested memory allocation of 2200MiB does not leave room for system overhead (total system memory: 2963MiB). You may face stability issues.
💡  建议:Start minikube with less memory allocated: 'minikube start --memory=2200mb'


🧯  The requested memory allocation of 2200MiB does not leave room for system overhead (total system memory: 2963MiB). You may face stability issues.
💡  建议:Start minikube with less memory allocated: 'minikube start --memory=2200mb'

👍  Starting control plane node minikube in cluster minikube
🚜  Pulling base image ...
🤷  docker "minikube" container is missing, will recreate.
🔥  Creating docker container (CPUs=2, Memory=2200MB) ...
❗  This container is having trouble accessing https://registry.cn-hangzhou.aliyuncs.com/google_containers
💡  To pull new external images, you may need to configure a proxy: https://minikube.sigs.k8s.io/docs/reference/networking/proxy/
🐳  正在 Docker 19.03.2 中准备 Kubernetes v1.20.2…
    ▪ Generating certificates and keys ...
    ▪ Booting up control plane ...
    ▪ Configuring RBAC rules ...
🔎  Verifying Kubernetes components...
🌟  Enabled addons: storage-provisioner, default-storageclass
🏄  Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default

# 获取
ubuntu@k8s-master:~$ kubectl get pods
No resources found in default namespace.
#创建一个
ubuntu@k8s-master:~$ kubectl run --image=nginx nginx-app --port=80
pod/nginx-app created
# 查询状态
ubuntu@k8s-master:~$ kubectl get pods
NAME        READY   STATUS              RESTARTS   AGE
nginx-app   0/1     ContainerCreating   0          35s
ubuntu@k8s-master:~$ kubectl get pods
\NAME        READY   STATUS    RESTARTS   AGE
nginx-app   1/1     Running   0          2m37s

curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.10.0/kind-linux-amd64
chmod +x ./kind
mv ./kind /some-dir-in-your-PATH/kind
root@k8s-master:/# kind version
kind v0.10.0 go1.15.7 linux/amd64

创建 Cluster

kind create cluster # Default cluster context name is `kind`.`
sudo apt-get update && sudo apt-get install -y apt-transport-https curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
cat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl

你需要在每台机器上安装以下的软件包:
kubeadm:用来初始化集群的指令。
kubelet:在集群中的每个节点上用来启动 Pod 和容器等。
kubectl:用来与集群通信的命令行工具。

root@k8s-master:/# kubeadm version
kubeadm version: &version.Info{Major:"1", Minor:"20", GitVersion:"v1.20.2", GitCommit:"faecb196815e248d3ecfb03c680a4507229c2a56", GitTreeState:"clean", BuildDate:"2021-01-13T13:25:59Z", GoVersion:"go1.15.5", Compiler:"gc", Platform:"linux/amd64"}