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

  

 

 

 

 

 

 

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM