#环境:VMwareworkstation创建的centos7.9虚拟机(4核8G、20GB硬盘)

(PS:至少需要2核2G要不然后续会报错)

#关闭selinux,关闭防火墙

#新建一个用户admin,后续操作都用admin账户进行操作

在 Linux 系统中安装并设置 kubectl | Kubernetes

minikube start | minikube

#安装minukube

下载minikube安装包

curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64

安装minkube

sudo install minikube /usr/local/bin/

检查minikube

minikube version

#安装kubectl

下载kubectl安装包

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/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256"

验证

echo "$(cat kubectl.sha256) kubectl" | sha256sum --check

安装

sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl

查看版本

kubectl version --client

#安装docker

yum install -y yum-utils

yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

yum makecache fast

yum install -y docker-ce docker-ce-cli containerd.io

#启动docker并设置开机启动

systemctl start docker

systemctl enable docker

#启动minukube

sudo usermod -aG docker $USER && newgrp docker

systemctl restart docker

minikube start --driver=docker

kubectl get po -A

minikube status

#kubectl创建nginx

kubectl create deployment mynginx --image=nginx:alpine

kubectl get pods

kubectl get deployments

#需要通过创建一个 Service 来暴露 Pod 才能实现集群外部访问

kubectl expose deployment mynginx --type=NodePort --port=80 --target-port=80

kubectl get services

#本机访问

minikube ip

kubectl get services

get svc mynginx

NodePort为32630

curl 192.168.49.2:32630

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐