rehl搭建k8s环境

一. 安装依赖

1.1 安装 docker

wget -O /etc/yum.repos.d/redhat.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/Centos-7.repo
sed -i 's/$releasever/7/' /etc/yum.repos.d/epel.repo
sed -i 's/$releasever/7/' /etc/yum.repos.d/redhat.repo
yum clean all 
yum makecache

cat <<EOF > /etc/sysctl.d/docker.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.conf.default.rp_filter = 0
net.ipv4.conf.all.rp_filter = 0
net.ipv4.ip_forward = 1
EOF

sysctl -p /etc/sysctl.d/docker.conf
modprobe br_netfilter
sysctl -p /etc/sysctl.d/docker.conf
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum makecache
yum list docker-ce --showduplicates | sort -r
yum install docker-ce-23.0.0 -y
mkdir -p /etc/docker && touch /etc/docker/daemon.json
tee /etc/docker/daemon.json <<-'EOF'
{
    "registry-mirrors": ["https://4efi3n2i.mirror.aliyuncs.com"]
}
EOF

systemctl daemon-reload
systemctl start docker.service
##开启自启动docker
systemctl enable docker
dockerd #若启动docker失败,可用此命令查看

1.2 安装conntrack

yum install conntrack -y

1.3 下载包

curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-latest.x86_64.rpm
rpm -Uvh minikube-latest.x86_64.rpm
# 查看minikube版本
minikube version 

curl -LO https://dl.k8s.io/release/v1.27.4/bin/linux/amd64/kubectl
chmod +x kubectl
mv kubectl /usr/local/bin/

二.创建 k8s 环境

minikube start --driver=none --image-mirror-country='cn' --image-repository='registry.cn-hangzhou.aliyuncs.com/google_containers' --kubernetes-version=v1.24.7

三.验证环境

# minikube status
minikube
type: Control Plane
host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured

# minikube node list
minikube	192.168.110.129

使用 kubectl 操作

# minikube kubectl -- version
WARNING: This version information is deprecated and will be replaced with the output from kubectl version --short.  Use --output=yaml|json to get the full version.
Client Version: version.Info{Major:"1", Minor:"24", GitVersion:"v1.24.7", GitCommit:"e6f35974b08862a23e7f4aad8e5d7f7f2de26c15", GitTreeState:"clean", BuildDate:"2022-10-12T10:57:14Z", GoVersion:"go1.18.7", Compiler:"gc", Platform:"linux/amd64"}
Kustomize Version: v4.5.4
Server Version: version.Info{Major:"1", Minor:"24", GitVersion:"v1.24.7", GitCommit:"e6f35974b08862a23e7f4aad8e5d7f7f2de26c15", GitTreeState:"clean", BuildDate:"2022-10-12T10:50:21Z", GoVersion:"go1.18.7", Compiler:"gc", Platform:"linux/amd64"}

给minikube kubectl起别名
alias kubectl="minikube kubectl --"

添加命令自动补全的功能
source <(kubectl completion bash)
Kubernetes 里运行一个 Nginx 应用,并查看Pod列表

# kubectl run ngx --image=nginx:alpine
pod/ngx created
# kubectl get Pod
NAME   READY   STATUS    RESTARTS   AGE
ngx       1/1           Running     0                 22s

minikube 环境已经搭建成功

参考链接

Redhat8安装docker
记一次解决用minicube start遇到的问题
https://minikube.sigs.k8s.io/docs/faq/#how-do-i-install-containernetworking-plugins-for-none-driver
https://minikube.sigs.k8s.io/docs/start/

你可能感兴趣的:(k8s,kubernetes,容器,云原生)