k8s开发环境安装
Linux下 相关软件安装
1. minikube安装
**********************!!!PROTECTION POLICY!!!**********************
Waiting For The Next Deployment, Maybe It Will Be Displayed After That.
2. docker安装
sudo apt install docker.io -y
3. podman安装
sudo apt update
sudo apt -y install software-properties-common
sudo add-apt-repository -y ppa:projectatomic/ppa
sudo apt -y install podman
cat > /etc/containers/registries.conf << EOF
unqualified-search-registries = ["docker.io"]
[[registry]]
prefix = "docker.io"
location = "uyah70su.mirror.aliyuncs.com"
EOF
# Debian Unstable/Sid
echo 'deb http://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/Debian_Unstable/ /' > /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list
curl -L https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/Debian_Unstable/Release.key | sudo apt-key add -
# Debian Testing
echo 'deb http://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/Debian_Testing/ /' > /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list
curl -L https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/Debian_Testing/Release.key | sudo apt-key add -
# Debian 10
echo 'deb http://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/Debian_10/ /' > /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list
curl -L https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/Debian_10/Release.key | sudo apt-key add -
sudo apt-get update -qq
sudo apt-get -qq -y install podman
minikube 基本使用
1. minikube 启动集群
minikube start --image-mirror-country cn --iso-url=https://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/iso/minikube-v1.11.0.iso --registry-mirror https://uyah70su.mirror.aliyuncs.com
# registry-mirror 影响docker镜像拉取速度 最好使用镜像站
2. 查询集群状态
minikube status
minikube dashboard
minikube addons list
3. 连接到内部集群
minikube ssh
# 内部集群可使用docker、podman命令直接管理容器
4. 停止集群
**********************!!!PROTECTION POLICY!!!**********************
Waiting For The Next Deployment, Maybe It Will Be Displayed After That.
5. 删除集群
minikube delete
rm -rf ~/.minikube ~/.kube
6. 获取容器环境
**********************!!!PROTECTION POLICY!!!**********************
Waiting For The Next Deployment, Maybe It Will Be Displayed After That.
* virtualbox 虚拟机跨操作系统共享
相关目录路径
系统类型 | minikube涉及配置 | kubectl涉及配置 | vbox涉及配置 |
---|---|---|---|
Linux | ~/.minikube | ~/.kube | ~/.config/VirtualBox |
Windows | ~/.minikube | ~/.kube | ~/.VirtualBox |
在VirtualBox媒介管理界面内将容器虚拟机的挂载磁盘释放掉,并注册加载共享的磁盘,在虚拟机下挂载注册好的磁盘;Linux下最好使用文件管理器覆盖证书秘钥等文件,避免文件权限不符问题;在VirtualBox网卡配置里将网卡ip和mac地址内容覆盖使之与虚拟机内已有配置匹配,修改目录内相关ip端口等使之相符
kubectl 基本使用
1. 常用操作
# minikube kubectl -- get nodes
# 可使用 minikube kubectl -- 代替 kubectl 命令
kubectl get nodes
kubectl get pods
kubectl get namespaces
kubectl create namespace development
kubectl create namespace qa
kubectl run nginx --image=nginx:latest --namespace development
kubectl describe pod nginx -n development
kubectl get pods --all-namespaces -o wide
kubectl delete namespaces development qa
kubectl delete pods nginx-674ff86d-4qjgk
kubectl get services,deployment -n default
kubectl get all -n development
kubectl get services --sort-by=.metedate.name
kubectl get pods --sort-by='.status.containerStatuses[0].restartCount'
kubectl describe deployment nginx
kubectl describe pod nginx
kubectl describe nodes
**********************!!!PROTECTION POLICY!!!**********************
Waiting For The Next Deployment, Maybe It Will Be Displayed After That.
kubectl config current-context
kubectl config get-contexts
kubectl config use-context mycluster
kubectl config set-context --current --namespace=dev-frontend
kubectl create deployment nginx --image=nginx:latest
kubectl expose deployment nginx --port=80 --type=NodePort
kubectl expose pod nginx --port=80 --type=NodePort --name=nginx1 -n default
kubectl create configmap -h
kubectl create -f app-manifest.yaml
kubectl create -f deployment.yaml -f service.yaml
kubectl create -f ./webapp
kubectl create -f https://xxx.xxx.xxx/deployment.yaml
cat <<EOF | kubectl create -f -
apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
EOF