Minikube已在环境中安装和配置。通过运行minikube version命令,检查是否已正确安装:
minikube version
Start the cluster, by running the minikube start command:
通过运行minikube start命令启动集群:
minikube start
Great! You now have a running Kubernetes cluster in your online terminal. Minikube started a virtual machine for you, and a Kubernetes cluster is now running in that VM.
太棒了!现在,您的在线终端中有一个正在运行的Kubernetes集群。Minikube为您启动了一个虚拟机,一个Kubernetes集群现在正在该VM中运行。
$ minikube version minikube version: v0.34.1 $ minikube start o minikube v0.34.1 on linux (amd64) > Configuring local host environment ... > Creating none VM (CPUs=2, Memory=2048MB, Disk=20000MB) ... - "minikube" IP address is 172.17.0.20 - Configuring Docker as the container runtime ... - Preparing Kubernetes environment ... @ Downloading kubeadm v1.13.3 @ Downloading kubelet v1.13.3 - Pulling images required by Kubernetes v1.13.3 ... - Launching Kubernetes v1.13.3 using kubeadm ... - Configuring cluster permissions ... - Verifying component health ..... + kubectl is now configured to use "minikube" = Done! Thank you for using minikube!
step: 集群信息:
集群及其健康状态的详细信息可以通过kubectl cluster info找到。
kubectl cluster-info
使用kubectl get nodes查看集群中的节点
如果节点标记为NotReady,则它仍在启动组件。
$ kubectl cluster-info Kubernetes master is running at https://172.17.0.20:8443 KubeDNS is running at https://172.17.0.20: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 nodes NAME STATUS ROLES AGE VERSION minikube Ready master 19m v1.13.3
step3: 部署容器
通过运行Kubernetes集群,现在可以部署容器。
使用kubectl run
,它允许将容器部署到集群上-kubectl run first-deployment --image=katacoda/docker-http-server --port=80
部署的状态可以通过运行的Pods来发现-kubectl get pods
一旦容器运行,根据需要,它可以通过不同的网络选项公开。最常用的解决方案是NodePort,它为容器提供动态端口。
kubectl expose deployment first-deployment --port=80 --type=NodePort
下面的命令查找分配的端口并执行HTTP请求。
export PORT=$(kubectl get svc first-deployment -o go-template='{{range.spec.ports}}{{if .nodePort}}{{.nodePort}}{{"\n"}}{{end}}{{end}}') echo "Accessing host01:$PORT" curl host01:$PORT
结果是处理请求的容器。
$ kubectl run first-deployment --image=katacoda/docker-http-server --port=80 kubectl run --generator=deployment/apps.v1 is DEPRECATED and will be removed in a future version. Use kubectl run --generator=run-pod/v1 or kubectl create instead. deployment.apps/first-deployment created $ kubectl get pods NAME READY STATUS RESTARTS AGE first-deployment-5bc5c8cd58-ft7xc 1/1 Running 0 22s
$ export PORT=$(kubectl get svc first-deployment -o go-template='{{range.spec.ports}}{{if .nodePort}}{{.nodePort}}{{"\n"}}{{end}}{{end}}') $ echo "Accessing host01:$PORT" Accessing host01:32644 $ curl host01:$PORT <h1>This request was processed by host: first-deployment-5bc5c8cd58-ft7xc</h1>
启用仪表板minikube addons enable dashboard
通过部署以下YAML定义,使Kubernetes仪表板可用。这只适用于Katacoda。
kubectl apply -f /opt/kubernetes-dashboard.yaml
Kubernetes仪表板允许您在UI中查看应用程序。在此部署中,仪表板已在端口上可用。30000.
指向仪表板的URL是https:/[主机_子域]-30000-[KATACODA_HOST].Environment s.katacoda.com/
$ minikube addons enable dashboard - dashboard was successfully enabled $ kubectl apply -f /opt/kubernetes-dashboard.yaml service/kubernetes-dashboard-katacoda created
Kubernetes-开始使用Kubeadm
在这个场景中,您将了解如何使用Kubeadm引导Kubernetes集群。
Kubeadm解决了处理TLS加密配置、部署核心Kubernetes组件和确保其他节点可以轻松地加入集群的问题。生成的集群通过RBAC等机制得到保护。
有关Kubeadm的更多详情,请参阅https://github.com/kubernetes/kubeadm