K8s 入门

安装k8s

curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"

curl -LO "https://dl.k8s.io/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256"

这命令会下载2个 文件来。其中一个是校验文件,另一个

kubectl 是可工具命令。

install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl 会安装这个工具,实际就是拷贝。

kubectl version --client 可以用这命令了。

----------------------------------------

安装 minikube

https://minikube.sigs.k8s.io/docs/start/

 

minikube start

提示 Exiting due to DRV_AS_ROOT: The "docker" driver should not be used with root privileges.

需要新增用户

useradd  qgb

passwd qgb `1qQAZQAZ

su qgb


minikube start --driver=docker
这会打印如下,时间有点长,需要下载1G多东西
[qgb@caoyuanfeixue root]$ minikube start --driver=docker
?? minikube v1.19.0 on Centos 8.3.2011 (amd64)
? Using the docker driver based on user configuration
?? Starting control plane node minikube in cluster minikube
?? Pulling base image ...
?? Downloading Kubernetes v1.20.2 preload ...
> preloaded-images-k8s-v10-v1...: 491.71 MiB / 491.71 MiB 100.00% 11.81 Mi

> index.docker.io/kicbase/sta...: 357.67 MiB / 357.67 MiB 100.00% 1.97 MiB
? minikube was unable to download gcr.io/k8s-minikube/kicbase:v0.0.20, but successfully downloaded kicbase/stable:v0.0.20 as a fallback image
?? Creating docker container (CPUs=2, Memory=2200MB) .../ E0426 15:56:09.747534 123504 network_create.go:79] failed to find free subnet for docker network minikube after 20 attempts: no free private network subnets found with given parameters (start: "192.168.9.0", step: 9, tries: 20)

? Unable to create dedicated network, this might result in cluster IP change after restart: un-retryable: no free private network subnets found with given parameters (start: "192.168.9.0", step: 9, tries: 20)
? This container is having trouble accessing https://k8s.gcr.io
?? To pull new external images, you may need to configure a proxy: https://minikube.sigs.k8s.io/docs/reference/networking/proxy/
?? Preparing Kubernetes v1.20.2 on Docker 20.10.5 ...
? Generating certificates and keys ...
? Booting up control plane ...
? Configuring RBAC rules ...
?? Verifying Kubernetes components...
? Using image gcr.io/k8s-minikube/storage-provisioner:v5
?? Enabled addons: storage-provisioner, default-storageclass
?? Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default


[qgb@caoyuanfeixue root]$ kubectl get po -A
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system coredns-74ff55c5b-whzwb 1/1 Running 0 79m
kube-system etcd-minikube 1/1 Running 0 79m
kube-system kube-apiserver-minikube 1/1 Running 0 79m
kube-system kube-controller-manager-minikube 1/1 Running 0 79m
kube-system kube-proxy-nbvfx 1/1 Running 0 79m
kube-system kube-scheduler-minikube 1/1 Running 0 79m
kube-system storage-provisioner 1/1 Running 0 79m

kubectl create deployment hello-minikube --image=k8s.gcr.io/echoserver:1.4
kubectl expose deployment hello-minikube --type=NodePort --port=8080
minikube service --url hello-minikube

docker ps 可以看到有新的容器了
minikube 可以查看帮助

[qgb@caoyuanfeixue root]$ minikube tunnel
[sudo] password for qgb:
Status:
machine: minikube
pid: 2575130
route: 10.96.0.0/12 -> 172.17.0.3
minikube: Running
services: []
errors:
minikube: no errors
router: error adding Route: qgb is not in the sudoers file. This incident will be reported.

这个错误,需要设置linux

[qgb@caoyuanfeixue root]$ whereis sudoers
sudoers: /etc/sudoers /etc/sudoers.d /usr/share/man/man5/sudoers.5.gz

[root@caoyuanfeixue ~]# chmod u+w /etc/sudoers

[root@caoyuanfeixue ~]# vi /etc/sudoers

把 qgb 这个用户加入即可。

 

 kubectl get pods -n kube-system  // 获取pods

 kubectl get cs   //  get cluster status

 

K8s 入门

上一篇:html5开发学习 html5自学需要怎么学


下一篇:币圈量化交易萌新看过来--带你走近币圈量化(六)