Docker-K8s-Minikube方式创建集群
查看阿里修改后的 MiniKube 的稳定版列表
https://github.com/AliyunContainerService/minikube/branches/all
下载阿里修改后的 MiniKube
http://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/releases/v1.1.1/minikube-windows-amd64.exe
下载kubectl
https://storage.googleapis.com/kubernetes-release/release/v1.17.4/bin/windows/amd64/kubectl.exe
创建集群
minikube start --registry-mirror=https://registry.docker-cn.com
执行客户端命令
kubectl config view kubectl config get-contexts kubectl cluster-info minikube status minikube ssh
创建Pod及容器
pod_nginx.yml文件
apiVersion: v1 kind: Pod metadata: name: nginx labels: app: nginx spec: containers: - name: nginx image: nginx ports: - containerPort: 80
执行命令
kubectl create -f pod_nginx.yml kubectl get pods kubectl get pods -o wide # 默认进入第一个容器,如果Pod中有多个容器可以使用 -c 参数指定进入某个容器 kubectl exec -it nginx /bin/bash kubectl describe pods nginx # 本地端口映射pod端口 kubectl port-forward nginx 8080:80 kubectl delete -f pod_nginx.yml
ReplicationController
rc_nginx.yml文件
apiVersion: v1 kind: ReplicationController metadata: name: nginx spec: replicas: 3 selector: app: nginx template: metadata: name: nginx labels: app: nginx spec: containers: - name: nginx image: nginx ports: - containerPort: 80
执行命令
kubectl.exe create -f .\rc_nginx.yml kubectl.exe get pods kubectl.exe get rc # 删掉一个pod验证可用性 kubectl.exe delete pods nginx-sshwd kubectl.exe scale rc nginx --replicas=4 kubectl.exe get rc
ReplicaSet
rs_nginx.yml文件
apiVersion: apps/v1 kind: ReplicaSet metadata: name: nginx labels: tier: frontend spec: replicas: 3 selector: matchLabels: tier: frontend template: metadata: name: nginx labels: tier: frontend spec: containers: - name: nginx image: nginx ports: - containerPort: 80
执行命令
kubectl.exe create -f .\rs_nginx.yml kubectl.exe get pods kubectl.exe get rs # 删掉一个pod验证可用性 kubectl.exe delete pods nginx-m6vj4 kubectl.exe scale rs nginx --replicas=4 kubectl.exe get rs
Deployment
deployment_nginx.yml文件
apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment labels: app: nginx spec: replicas: 3 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.12.2 ports: - containerPort: 80
执行命令
kubectl.exe create -f .\deployment_nginx.yml kubectl.exe get deployment -o wide kubectl.exe set image deployment nginx-deployment nginx=nginx:1.13 kubectl.exe get deployment -o wide kubectl.exe get pods kubectl.exe get rs kubectl.exe rollout history deployment nginx-deployment kubectl.exe rollout undo deployment nginx-deployment # 创建service,暴露pod端口 kubectl.exe expose deployment nginx-deployment --type=NodePort kubectl.exe delete service nginx-deployment