欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  科技

Minikube-Kubernetes本地环境进行开发

程序员文章站 2022-10-24 16:45:01
Minikube Kubernetes本地环境进行开发 使用Minikube 启动Minikube 获取命名空间 获取集群信息 获取节点信息 运行nginx 获取pods 查看Pod日志 进入Pod中 获取deployment 获取svc(services) 使用Minikube获取服务访问地址 删 ......

minikube-kubernetes本地环境进行开发

使用minikube

启动minikube

# 启动
minkube start

# 检查状态
minikube status

host: running
kubelet: running
apiserver: running
kubectl: correctly configured: pointing to minikube-vm at 192.168.99.100


# 访问面板
$ minikube dashboard

# 访问web前端
$ kubectl proxy

获取命名空间

# kubectl get namespaces
$ kubectl get ns
name              status   age
default           active   156m
kube-node-lease   active   156m
kube-public       active   156m
kube-system       active   156m

获取集群信息

$ kubectl cluster-info
kubernetes master is running at https://192.168.99.100:8443
kubedns is running at https://192.168.99.100:8443/api/v1/namespaces/kube-system/services/kube-
dns:dns/proxy

to further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

获取节点信息

$ kubectl get node

name       status   roles    age    version
minikube   ready    master   162m   v1.14.1

运行nginx

# 运行nginx
$ kubectl run nginx --image=nginx:1.16 --port=80 --labels="app=nginx,env=dev"

# 增加新标签
# kubectl label pod $pod_name app2=test

# 发布服务采用对外暴露节点
$ kubectl expose deployment nginx --type=nodeport

获取pods

$ kubectl get pods
# 根据标签查询
# kubectl get pods -l app=nginx

name                    ready   status    restarts   age
nginx-fcb945956-t8bqq   1/1     running   0          67s

# 获取pod详细信息
# kubectl describe pods -l app=nginx

查看pod日志

kubectl logs $pod_name

进入pod中

# 查看环境
# kubectl exec $pod_name env

$ kubectl exec -ti nginx-fcb945956-t8bqq /bin/bash

获取deployment

$ kubectl get deployment

name    ready   up-to-date   available   age
nginx   1/1     1            1           18m


# 获取描述
$ kubectl describe deployment

name:                   nginx
namespace:              default
creationtimestamp:      wed, 15 may 2019 23:29:23 +0800
labels:                 app=nginx
                        env=dev
annotations:            deployment.kubernetes.io/revision: 1
selector:               app=nginx,env=dev
replicas:               1 desired | 1 updated | 1 total | 1 available | 0 unavailable
strategytype:           rollingupdate
minreadyseconds:        0
rollingupdatestrategy:  25% max unavailable, 25% max surge
pod template:
  labels:  app=nginx
           env=dev
  containers:
   nginx:
    image:        nginx:1.16
    port:         8081/tcp
    host port:    0/tcp
    environment:  <none>
    mounts:       <none>
  volumes:        <none>
conditions:
  type           status  reason
  ----           ------  ------
  available      true    minimumreplicasavailable
  progressing    true    newreplicasetavailable
oldreplicasets:  <none>
newreplicaset:   nginx-fcb945956 (1/1 replicas created)
events:
  type    reason             age   from                   message
  ----    ------             ----  ----                   -------
  normal  scalingreplicaset  18m   deployment-controller  scaled up replica set nginx-fcb945956 to 1

获取svc(services)

# kubectl get svc
$ kubectl get services

name         type        cluster-ip      external-ip   port(s)        age
kubernetes   clusterip   10.96.0.1       <none>        443/tcp        3h8m
nginx        nodeport    10.105.192.17   <none>        80:31199/tcp   5m9s

# 获取详情
$ kubectl describe services

name:              kubernetes
namespace:         default
labels:            component=apiserver
                   provider=kubernetes
annotations:       <none>
selector:          <none>
type:              clusterip
ip:                10.96.0.1
port:              https  443/tcp
targetport:        8443/tcp
endpoints:         192.168.99.100:8443
session affinity:  none
events:            <none>


name:                     nginx
namespace:                default
labels:                   app=nginx
                          env=dev
annotations:              <none>
selector:                 app=nginx,env=dev
type:                     nodeport
ip:                       10.105.192.17
port:                     <unset>  80/tcp
targetport:               80/tcp
nodeport:                 <unset>  31199/tcp
endpoints:                172.17.0.5:80
session affinity:         none
external traffic policy:  cluster
events:                   <none>

使用minikube获取服务访问地址

# 获取服务url
$ minikube service nginx --url

# 访问测试
$ curl $(minikube service nginx --url)

删除服务

# kubectl delete deployments --all
$ kubectl delete deployments -l app=nginx

# kubectl delete pods --all
$ kubectl delete pods -l app=nginx

# 删除service
kubectl delete service -l app=nginx

停止minikube

minikube stop

参考

k8s官网文档

minikube - kubernetes本地实验环境

minikube:使用 kubernetes 进行本地开发

kubernetes基础:查看状态、管理服务