In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to build a Kubernetes cluster in Minikube, which has a certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let's take a look at it.
Minikube
Open https://github.com/kubernetes/minikube/releases/tag/v1.19.0 to download the latest version of the binary package (deb, rpm package), and then install it using apt or yum.
Or download the latest version of minikube binaries directly (recommended).
Curl-Lo minikube https://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/releases/v1.19.0/minikube-linux-amd64# is the version built by Aliyun. If you build it using google, you need to flip through qiang. # linux version curl-Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64#win version curl-Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-darwin-amd64chmod + x minikubesudo mv minikube / usr/local/bin
You can see the version of minikube through the minikube version command, and then you can create a kubernetes cluster directly using the minikube start command. Minikube automatically downloads kubeadm, kubectl, and kubelet.
If it doesn't start, you can create a docker user.
After useradd-m docker passwd docker # changes the password, join the user group gpasswd-a docker docker
Open the / etc/sudoers file and add a new line under root ALL= (ALL:ALL) ALL:
Docker ALL= (ALL) ALL
Then switch to the docker user: su docker.
The author's note: if you start the minikube command with a root user, you will get an error and you need to use a non-root user (usually docker). If you don't want to switch to another user, use-- driver==none.
Minikube start-- driver=none* Pulling base image... * Downloading Kubernetes v1.20.2 preload... > preloaded-images-k8s-v10-v1...: 491.71 MiB / 491.71 MiB 100.004 60.04 Mi > gcr.io/k8s-minikube/kicbase...: 357.67 MiB / 357.67 MiB 100.004 7.41 MiB* Creating docker container (CPUs=2, Memory=4000MB). /
Next, minikube will pull various images, which will take some time. After the minikube is initialized, open a new terminal window and execute the minikube dashboard startup panel, which can be accessed according to the URL address.
PS: if you report X Exiting due to GUEST_MISSING_CONNTRACK: Sorry, Kubernetes 1.20.2 requires conntrack to be installed in root's path, you need to install constrack and apt install constrack.
Normally, this is what happens after docker ps is executed.
Script
If you find it troublesome. You can use a script.
Create a new start.sh with the following file content:
Echo-n "Starting Kubernetes..." minikube versionminikube start-- wait=falsesleep 2n=0until [$n-ge 10] do minikube addons enable dashboard & & break nasty $[$n-ge 10] sleep 1donesleep 1n=0until [$n-ge 10] do kubectl apply-f / opt/kubernetes-dashboard.yaml & > / dev/null & & break nasty $[$nasty 1] sleep 1doneecho "Kubernetes Started"
Create a new kubernetes-dashboard.yaml with the following file content:
ApiVersion: v1kind: Namespacemetadata: labels: addonmanager.kubernetes.io/mode: Reconcile kubernetes.io/minikube-addons: dashboard name: kubernetes-dashboard selfLink: / api/v1/namespaces/kubernetes-dashboardspec: finalizers:-kubernetesstatus: phase: Active---apiVersion: v1kind: Servicemetadata: labels: app: kubernetes-dashboard name: kubernetes-dashboard-katacoda namespace: kubernetes-dashboardspec: ports:-port: 80 protocol: TCP targetPort: 9090 nodePort: 30000 selector: k8s-app: kubernetes-dashboard type: NodePort
Put kubernetes-dashboard.yaml in the / opt directory.
Then start the start.sh.
Create Deployment
Kubernetes Deployment can check the health of the Pod and restart the new container if the container in the Pod terminates.
Deployment can deploy applications and manage the number of instances. It provides a self-healing mechanism. When an application dies, deployment can automatically start a new instance and maintain a fixed number of pod.
The kubectl create command creates a Deployment that manages the Pod.
Kubectl create deployment hello-node-- image=k8s.gcr.io/echoserver:1.4# k8s.gcr.io/echoserver:1.4 is the name of the image, and hello-node is the name of node
The k8s.gcr.io/echoserver image exposes port 8080.
View Deployment:
Kubectl get deployments
View pod:
Kubectl get pods
View cluster events:
Kubectl get events
View the kubectl configuration:
Kubectl config view creates Service
By default, pod can only be accessed on the internal network of the kubernetes cluster, and if you want external network access, you need to expose the pod as kubnetes service. Here we expose the hello-node node from the previous section.
Kubectl expose deployment hello-node-type=LoadBalancer-port=8080
Then look at the service you just created:
Kubectl get servicesNAME TYPE CLUSTER-IP EXTERNAL-IP PORT (S) AGEhello-node LoadBalancer 10.96.194.154 8080:31686/TCP 85skubernetes ClusterIP 10.96.0.1 443/TCP 22m
Then try minikube service to provide an ip for outside access.
Minikube service hello-noderoot@instance-1:~# minikube service hello-node |-| | NAMESPACE | NAME | TARGET PORT | URL | |-|- -| | default | hello-node | 8080 | http://10.170.0.2:31686 | |- -| * Opening service default/hello-node in default browser... Http://10.170.0.2:31686 cleans up cluster resources
First generate service and deployment.
Kubectl delete service hello-nodekubectl delete deployment hello-node
Then stop the Minikube virtual machine (VM):
Minikube stop
Then delete the Minikube virtual machine (VM):
Minikube delete thank you for reading this article carefully. I hope the article "how to build a Kubernetes Cluster in Minikube" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.