这是一篇 K8S 的 HelloWorld,在学习K8S官方文档时搭建环境搭建的一个记录,照着文档下来还是比较顺利的。

一、安装kubectl

下载 kubectl
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" 下载 checksum
curl -LO "https://dl.k8s.io/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256" 检查sha265sum
arvin@ubuntu:~$ echo "$(<kubectl.sha256) kubectl" | sha256sum --check
kubectl: OK 安装
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl 安装结果
arvin@ubuntu:~$ kubectl version --client
Client Version: version.Info{Major:"1", Minor:"21", GitVersion:"v1.21.1", GitCommit:"5e58841cce77d4bc13713ad2b91fa0d961e69192", GitTreeState:"clean", BuildDate:"2021-05-12T14:18:45Z", GoVersion:"go1.16.4", Compiler:"gc", Platform:"linux/amd64"}

二、安装minikube

minikube是本地的Kubernetes,致力于使Kubernetes易于学习和开发。

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

三、启动minikube

minikube start

四、碰到的问题

1.提示docker 驱动不能与管理员权限一起使用

arvin@ubuntu:~$ sudo minikube start

minikube v1.20.0 on Ubuntu 20.10

Automatically selected the docker driver. Other choices: none, ssh

The "docker" driver should not be used with root privileges.

If you are running minikube within a VM, consider using --driver=none:

https://minikube.sigs.k8s.io/docs/reference/drivers/none/

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

2.提示docker 没有权限

arvin@ubuntu:~$ minikube start

minikube v1.20.0 on Ubuntu 20.10

Unable to pick a default driver. Here is what was considered, in preference order:

podman: Not installed: exec: "podman": executable file not found in $PATH

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

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

查阅docker 手册

The docker daemon binds to a Unix socket instead of a TCP port. By

default that Unix socket is owned by the user root and other users can

only access it using sudo. The docker daemon always runs as the root

user.

If you don’t want to use sudo when you use the docker command, create

a Unix group called docker and add users to it. When the docker daemon

starts, it makes the ownership of the Unix socket read/writable by the

docker group.

解决办法

arvin@ubuntu:~$ sudo groupadd docker    #添加docker用户组
groupadd: group 'docker' already exists
arvin@ubuntu:~$ sudo gpasswd -a $USER docker #将登陆用户加入到docker用户组中
Adding user arvin to group docker
arvin@ubuntu:~$ newgrp docker #更新用户组

五、运行minikube

成功启动

arvin@ubuntu:~$ minikube start
minikube v1.20.0 on Ubuntu 20.10
Automatically selected the docker driver. Other choices: none, ssh
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% 3.31 MiB
> index.docker.io/kicbase/sta...: 358.10 MiB / 358.10 MiB 100.00% 1.39 MiB
minikube was unable to download gcr.io/k8s-minikube/kicbase:v0.0.22, but successfully downloaded kicbase/stable:v0.0.22 as a fallback image
Creating docker container (CPUs=2, Memory=2200MB) ...
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.6 ...
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

查看kuberners 状态

minikube dashboard --url
Verifying dashboard health ...
Launching proxy ...
Verifying proxy health ...
http://127.0.0.1:34235/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/

六、部署Demo

创建一个develpment
kubectl create deployment hello-minikube --image=k8s.gcr.io/echoserver:1.4 kubectl expose deployment hello-minikube --type=NodePort --port=8080 arvin@ubuntu:~$ kubectl get services hello-minikube
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hello-minikube NodePort 10.96.129.107 <none> 8080:31559/TCP 46s arvin@ubuntu:~$ minikube service hello-minikube
|-----------|----------------|-------------|---------------------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|-----------|----------------|-------------|---------------------------|
| default | hello-minikube | 8080 | http://192.168.49.2:30064 |
|-----------|----------------|-------------|---------------------------|
Opening service default/hello-minikube in default browser... 发现网页无法访问
查看pod信息
arvin@ubuntu:~$ kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
hello-minikube-6ddfcc9757-njfpc 0/1 ImagePullBackOff 0 13m 172.17.0.5 minikube <none> <none> 发现处于imagepullbackoff 状态
查看pod 详细描述
arvin@ubuntu:~$ kubectl describe pod
Name: hello-minikube-6ddfcc9757-njfpc
Namespace: default
Priority: 0
Node: minikube/192.168.49.2
Start Time: Wed, 19 May 2021 00:38:52 +0800
Labels: app=hello-minikube
pod-template-hash=6ddfcc9757
Annotations: <none>
Status: Pending
IP: 172.17.0.5
IPs:
IP: 172.17.0.5
Controlled By: ReplicaSet/hello-minikube-6ddfcc9757
Containers:
echoserver:
Container ID:
Image: k8s.gcr.io/echoserver:1.4
Image ID:
Port: <none>
Host Port: <none>
State: Waiting
Reason: ImagePullBackOff
Ready: False
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-9rdjm (ro)
Conditions:
Type Status
Initialized True
Ready False
ContainersReady False
PodScheduled True
Volumes:
default-token-9rdjm:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-9rdjm
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 15m default-scheduler Successfully assigned default/hello-minikube-6ddfcc9757-njfpc to minikube
Normal Pulling 12m (x4 over 15m) kubelet Pulling image "k8s.gcr.io/echoserver:1.4"
Warning Failed 12m (x4 over 14m) kubelet Failed to pull image "k8s.gcr.io/echoserver:1.4": rpc error: code = Unknown desc = Error response from daemon: Get https://k8s.gcr.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
Warning Failed 12m (x4 over 14m) kubelet Error: ErrImagePull
Warning Failed 12m (x6 over 14m) kubelet Error: ImagePullBackOff
Normal BackOff 4m56s (x35 over 14m) kubelet Back-off pulling image "k8s.gcr.io/echoserver:1.4" 发现是缺少镜像
minikube ssh
docker images arvin@ubuntu:~$ minikube ssh
Last login: Tue May 18 16:55:58 2021 from 192.168.49.1
docker@minikube:~$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
gcr.io/k8s-minikube/storage-provisioner v5 6e38f40d628d 7 weeks ago 31.5MB
k8s.gcr.io/kube-proxy v1.20.2 43154ddb57a8 4 months ago 118MB
k8s.gcr.io/kube-controller-manager v1.20.2 a27166429d98 4 months ago 116MB
k8s.gcr.io/kube-apiserver v1.20.2 a8c2fdb8bf76 4 months ago 122MB
k8s.gcr.io/kube-scheduler v1.20.2 ed2c44fbdd78 4 months ago 46.4MB
kubernetesui/dashboard v2.1.0 9a07b5b4bfac 5 months ago 226MB
k8s.gcr.io/etcd 3.4.13-0 0369cf4303ff 8 months ago 253MB
k8s.gcr.io/coredns 1.7.0 bfe3a36ebd25 11 months ago 45.2MB
kubernetesui/metrics-scraper v1.0.4 86262685d9ab 13 months ago 36.9MB
k8s.gcr.io/pause 发现没有我们刚才部署的镜像,这里我们下载一个镜像进行重新部署测试
下载镜像 docker@minikube:~$ docker pull cilium/echoserver
Using default tag: latest
latest: Pulling from cilium/echoserver
a6014dd53961: Pull complete
fedc7896051b: Pull complete
5500b395a348: Pull complete
880bf53d0210: Pull complete
94791026eeca: Pull complete
d51579691189: Pull complete
7fd34bf14970: Pull complete
4b12f3ef8e65: Pull complete
b0e3c31807a2: Pull complete
e0962580d825: Pull complete
46b541e4c252: Pull complete
Digest: sha256:d6bd1dee4502cc50a974a97563330b4caaa2ac5b00a20ad2b82f4aa0e25e14fe
Status: Downloaded newer image for cilium/echoserver:latest
docker.io/cilium/echoserver:latest 部署新的echoserver
kubectl create deployment testechoserver --image=cilium/echoserver
deployment.apps/testechoserver created arvin@ubuntu:~$ kubectl expose deployment testechoserver --type=NodePort --port=8080
service/testechoserver exposed 查看部署状态
arvin@ubuntu:~$ kubectl get deployment
NAME READY UP-TO-DATE AVAILABLE AGE
hello-minikube 0/1 1 0 26m
testechoserver 1/1 1 1 2m12s 查看创建的服务
arvin@ubuntu:~$ kubectl get services testechoserver
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
testechoserver NodePort 10.106.69.154 <none> 8080:32617/TCP 2m3s 设置端口转发
arvin@ubuntu:~$ kubectl port-forward service/testechoserver 7080:8080
Forwarding from 127.0.0.1:7080 -> 8080
Forwarding from [::1]:7080 -> 8080 使用curl 查看信息
arvin@ubuntu:~$ curl http://127.0.0.1:7080 Hostname: testechoserver-5668cd9764-jslfz Pod Information:
-no pod information available- Server values:
server_version=nginx: 1.13.3 - lua: 10008 Request Information:
client_address=::ffff:127.0.0.1
method=GET
real path=/
query=
request_version=1.1
request_scheme=http
request_uri=http://127.0.0.1:8080/ Request Headers:
accept=*/*
host=127.0.0.1:7080
user-agent=curl/7.68.0 Request Body:
-no body in request-

七、管理集群

minikube 的一些命令

暂停集群而不影响部署的应用程序
minikube pause 停止集群,相对应的是minikube start启动集群
minikube stop 设置内存大小为2048MB,设置后创建新的集群会使用改配置
minikube config set memory 2048 查看扩展插件信息
minikube addons list 删除集群
minikube delete 具体可根据minikube --help 查看学习

Kubernetes入门,使用minikube 搭建本地k8s 环境的更多相关文章

  1. [kubernetes] 使用 Minikube 快速搭建本地 k8s 环境 (基于 Docker 驱动模式)

    一.实验环境 操作系统:Centos 7 x86_64 Docker:1.12.6 二.部署 k8s 步骤 2.1  安装 kubectl cat <<EOF > /etc/yum. ...

  2. 利用Docker Compose快速搭建本地测试环境

    前言 Compose是一个定义和运行多个Docker应用的工具,用一个YAML(dockder-compose.yml)文件就能配置我们的应用.然后用一个简单命令就能启动所有的服务.Compose编排 ...

  3. JBOSS安装与配置搭建本地项目环境(方便前端开发调式)

    JBOSS安装与配置搭建本地项目环境  什么是JBOSS? JBOSS是EJB的服务器,就像Tomcat是JSP服务器一样,就是服务器的一种. 环境搭建如下: 一:首先安装JDK,配置环境变量(PAT ...

  4. 使用WampServer搭建本地PHP环境,绑定域名,配置伪静态

    倡萌之前介绍过 USBWebserver 快速搭建本地PHP环境 ,推荐USBWebserver的原因在于它是绿色的,不需要安装,想使用就手动运行下即可.但是 USBWebserver 也有自身的弱点 ...

  5. 利用Docker搭建本地https环境的完整步骤

    利用Docker搭建本地https环境的完整步骤 这篇文章主要给大家介绍了关于如何利用Docker搭建本地https环境的完整步骤,文中通过示例代码将实现的步骤介绍的非常详细,对大家的学习或者工作具有 ...

  6. 本地k8s环境minikube搭建过程

    首先要安装docker这个环境是需要自己安装的.相关步骤如下: 1 2 3 4 5 6 7 8 9 10 11 yum install -y yum-utils device-mapper-persi ...

  7. 入门Kubernetes-minikube本地k8s环境

    前言: 在上一篇 结尾中使用到了minikube方式来做k8s本地环境来学习k8s. 那么这篇先了解下minikube及使用 一.Minikube 简介 minikube 在 macOS.Linux ...

  8. K8s炼气期(一)| minikube安装本地Kubenetes环境

    前言 根据Kubenetes学习路径的七大阶段,炼气期.筑基期.金丹期.元婴期.化神期.炼虚期.大乘期:开始炼气期的第一个小阶段,安装Kubenetes环境. 目录 1.安装kubectl 2.安装m ...

  9. 使用 phpstudy 搭建本地测试环境

    最近在为另一个部门配置一个多语言的网站,因为之前他们已经做过 英文和中文两种语言,这次帮他们添加其它几种语言,从GitLab 上拉下来的代码,是php环境做的,需要在本地跑起来,做完测试通过后再一次性 ...

随机推荐

  1. Linux Python2 升级到 Python3

    国内企业服务器用 CentOS 系统的比较多,CentOS8 系统已经将系统默认 Python 版本调整为了 Python3,但是 CentOS7 的存量还是很大,毕竟对企业生产服务来说稳定大于一切, ...

  2. 【RTOS】堆栈与任务栈

    目录 前言 概念 双堆栈指针 要点 Cortex-M3寄存器介绍 寄存器图 简要介绍 知识 出入栈 入栈(压栈) 出栈 重点知识 异常的响应序列* 入栈 取向量 更新寄存器 小结知识* FreeRTO ...

  3. 17. vue-route详细介绍

    前后端路由的来历 前端如何实现页面跳转但是不刷新? 了解hash和history两种方法 vue-router基本使用 安装vue-router 搭建vue-router框架的步骤 vue-route ...

  4. SpringBoot-11 扩展功能

    SpringBoot-11 扩展功能 异步 同步就是一个任务的完成需要依赖另外一个任务时,只有等待被依赖的任务完成后,依赖的任务才能算完成,这是一种可靠的任务序列.要么成功都成功,失败都失败,两个任务 ...

  5. DAOS 分布式异步对象存储|数据平面

    DAOS 通过两个紧密集成的平面进行运转.数据平面处理繁重的运输操作,而控制平面负责进程编排和存储管理,简化数据平面的操作. 模块接口 I/O 引擎支持一个模块接口,该接口允许按需加载服务器端代码.每 ...

  6. 三次给你讲清楚Redis之Redis是个啥

    摘要:Redis是一款基于键值对的NoSQL数据库,它的值支持多种数据结构:字符串(strings).哈希(hashes).列表(lists).集合(sets).有序集合(sorted sets)等. ...

  7. Asp.Net Core 5 REST API 使用 JWT 身份验证 - Step by Step

    翻译自 Mohamad Lawand 2021年1月22日的文章 <Asp Net Core 5 Rest API Authentication with JWT Step by Step> ...

  8. 自动化kolla-ansible部署ubuntu20.04+openstack-victoria之vmware设置-02

    自动化kolla-ansible部署ubuntu20.04+openstack-victoria之vmware设置-02 欢迎加QQ群:1026880196  进行讨论 1. vmwae版本 2. 网 ...

  9. Java面向对象OOP思想概述

    目录 OOP思想(Object Oriented Programming) 类和对象 接口 抽象类 OOP三大特性 封装 继承 多态 OOP复用的形式 OOP思想(Object Oriented Pr ...

  10. Day14_79_IO+Properties联合应用

    IO+Properties联合应用 - dbinfo文件中可以存放<key=value> - 像dbinfo这样的文件我们叫做配置文件,配置文件的作用是使程序更加灵活 - 一般在程序中可变 ...