Kubernetes Minikube

centos7

安装VirtualBox

/etc/yum.repos.d/下新建VirtualBox.repo文件,内容如下:

[virtualbox]
name=Oracle Linux / RHEL / CentOS-$releasever / $basearch - VirtualBox
baseurl=http://download.virtualbox.org/virtualbox/rpm/el/$releasever/$basearch
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://www.virtualbox.org/download/oracle_vbox.asc

执行如下的命令安装VirtualBox

yum install VirtualBox-5.2

注意: 由于VirtualBox不能安装在虚拟机内,所以像阿里云这种云平台里的主机都是不能用来安装Minikube的,只能在非虚拟机内使用;

启动Minikube

chenzhenyang@chenzhenyang:~/kubernetes-workspace$ minikube start --registry-mirror=https://registry.docker-cn.com
chenzhenyang@chenzhenyang:~/kubernetes-workspace$ minikube addons list
- coredns: disabled
- heapster: enabled
- efk: disabled
- addon-manager: enabled
- default-storageclass: enabled
- kube-dns: enabled
- ingress: enabled
- registry: disabled
- registry-creds: disabled
- dashboard: enabled
- storage-provisioner: enabled

查看kube-dns/ingress/dashboard等是否开启,minikube addons enable xx可以开启指定的addon;

创建应用

目标:创建一个Deployment,让K8s根据Deployment的配置,自动创建两个Tomcat9容器,在Pod之上创建一个Service,在Service之上创建Ingress对象;
[tomcat9-deployment.yaml]

apiVersion: apps/v1beta2
kind: Deployment
metadata: 
  name: tomcat-deployment
spec:
  selector: 
    matchLabels: 
      app: tomcat9
  replicas: 2
  template:
    metadata:
      labels:
        app: tomcat9
    spec: 
      containers:
      - name: tomcat9
        image: tomcat:9
        ports: 
        - containerPort: 8080

[tomcat9-service.yaml]

apiVersion: v1
kind: Service
metadata: 
  name: tomcat9
spec:
  type: NodePort
  ports:
  - port: 8080
    targetPort: 8080
    nodePort: 31001
  selector:
    app: tomcat9

[tomcat9-ingress.yaml]

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: tomcat9-ingress
  annotations:
    ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - http:
      paths:
      - path: /docs
        backend:
          serviceName: tomcat9
          servicePort: 8080

验证

tomcat

chenzhenyang@chenzhenyang:~/kubernetes-workspace$ kubectl cluster-info //获取集群的IP地址

tomcat主页面:http://cluster-info#ip:31001
tomcat doc页面:https://cluster-info#ip/docs/

kube api service local proxy

chenzhenyang@chenzhenyang:~/kubernetes-workspace$ kubectl proxy

在本机开启8001端口,代理minikube集群的Kube Api Server服务;

addon与service

chenzhenyang@chenzhenyang:~/kubernetes-workspace$ kubectl get service --all-namespaces=true

执行上边的命令发现kube-system下有如下的service

kube-system   default-http-backend   NodePort    10.0.0.212   <none>        80:30001/TCP        4h
kube-system   heapster               ClusterIP   10.0.0.70    <none>        80/TCP              4h
kube-system   kubernetes-dashboard   NodePort    10.0.0.190   <none>        80:30000/TCP        5h
kube-system   monitoring-grafana     NodePort    10.0.0.97    <none>        80:30002/TCP        4h
kube-system   monitoring-influxdb    ClusterIP   10.0.0.252   <none>        8083/TCP,8086/TCP   4h

这是enable了对应的addon,kubernetes自己创建的;这些service的名字和对于addon的名字可以直接对上号;default-http-backend Service是开启了Ingress addon之后,K8s创建的,主要是在通过Ingress访问Service时提供404等通用页面;

参考

Running Kubernetes Locally via Minikube
https://www.virtualbox.org/wiki/Linux_Downloads
Minikube - Kubernetes本地实验环境
Minikube:轻松创建单机版 Kubernetes 集群
Kubernetes - 使用kubectl proxy

你可能感兴趣的:(Kubernetes)