# Minikube单机版k8s实验环境

CentOS 7安装minikube

**一、安装Docker-CE**

```bash
# 安装包依赖、添加原件源、更新yum缓存、安装docker-ce、docker启动
yum install -y yum-utils device-mapper-persistent-data lvm2 wget
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum clean all && yum makecache fast
yum -y install docker-ce
systemctl start docker && systemctl enable docker
```

**二、安装kubectl**

```bash
# 下载二进制包，添加可执行权限，移动到bin目录，
# 因为我是root登录的所以是/usr/bin，其他用户登录是/usr/local/bin
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.18.0/bin/linux/amd64/kubectl &&\
chmod +x ./kubectl &&\
mv ./kubectl /usr/bin/kubectl
kubectl version --client
```

**三、安装minikube**

```bash
wget https://github.com/kubernetes/minikube/releases/download/v1.7.3/minikube-linux-amd64 &&\
mv minikube-linux-amd64 minikube &&\
chmod +x minikube &&\
mv minikube /usr/bin/
```

**四、启动minikube**

```bash
# 关闭默认自带防火墙; 
# 安装iptables管理工具，并清空规则;
# 关闭SELinux
# 关闭SWap
# 调整内核参数
systemctl stop firewalld && systemctl disable firewalld
yum -y install iptables-services && systemctl start iptables && systemctl enable iptables && iptables -F && service iptables save
setenforce 0 && sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
swapoff -a && sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab

cat > /etc/sysctl.d/kubernetes.conf <<EOF
net.bridge.bridge-nf-call-iptables=1
net.bridge.bridge-nf-call-ip6tables=1
net.ipv4.ip_forward=1
net.ipv4.tcp_tw_recycle=0
vm.swappiness=0             # 禁止使用 swap 空间，只有当系统 OOM 时才允许使用它
vm.overcommit_memory=1      # 不检查物理内存是否够用
vm.panic_on_oom=0           # 开启 OOM
fs.inotify.max_user_instances=8192
fs.inotify.max_user_watches=1048576
fs.file-max=52706963
fs.nr_open=52706963
net.ipv6.conf.all.disable_ipv6=1
net.netfilter.nf_conntrack_max=2310720
EOF

sysctl -p /etc/sysctl.d/kubernetes.conf
```

启动minikube

```bash
# 启动minikube下载所需镜像，不会用vbox所以用默认容器驱动启动的，切记要配置虚拟机DNS；
# cpus、memory为虚拟机分配核数、分配内存
minikube start --image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers \
    --cpus=2 \
    --memory=4096 \
    --vm-driver=none
```

添加阿里云加速器

```bash
cat > /etc/docker/daemon.json <<EOF
{
    "registry-mirrors": [
        "https://registry.docker-cn.com"
    ]
}
EOF

systemctl restart docker
```

```bash
[root@localhost ~]# kubectl get no
NAME                    STATUS   ROLES    AGE   VERSION
localhost.localdomain   Ready    master   64m   v1.17.3
```

**安装metric-server**

### 在 Minikube 环境中使用 NGINX Ingress 控制器配置 Ingress

> 参考： <https://kubernetes.io/zh/docs/tasks/access-application-cluster/ingress-minikube/>

```shell
minikube addons enable ingress
kubectl get pods -n kube-system
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://close.gitbook.io/yun-wei-bi-ji/kubernetes/k8s/minikube-dan-ji-ban-k8s-shi-yan-huan-jing.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
