To familiarize myself with the basic concepts mentioned above, I watched a video showing some of the features demonstrated by Minikube. So I thought I’d give Kubernetes a quick taste of some of its features.
Minikube installation
Drivers for Minikube
Minikube supports VM deployment, Container deployment, and bare-metal deployment. Bare-metal deployment is supported by VM deployment, Container deployment, and bare-Metal deployment. The modes supported by different platforms in official documents are shown below:
As you can see, Docker is officially recommended as the first choice. Most of the material on the web is basically based on VirtualBox, which I’ve tried with no problem.
VirtualBox
If you select VirtualBox, install and download the connection
The installation
There are a lot of minor issues with the recent high release of MacOS. The first is the Homebrew update issue. In addition, the higher version of MacOS is strict about security verification, so you need to grant permissions during installation. Otherwise, insufficient permissions will be reported. The complete command is as follows:
#Authorize, or an insufficient permission error is reported
sudo chown -R `whoami` /usr/local/Homebrew/
sudo chown -R $(whoami) $(brew --prefix)/*
sudo chown -R `whoami` /usr/local/Frameworks/
## minikube install command
brew install minikube
Copy the code
run
The biggest problem in the startup process is the network, if there is no VPN, or to replace the source to the domestic.
- Docker way
#Docker way
minikube start --image-repository='registry.cn-hangzhou.aliyuncs.com/google_containers'
Copy the code
The following figure shows that the startup is successful
- VirtualBox
# VirtualBox
minikube start --vm-driver=virtualbox --image-repository='registry.cn-hangzhou.aliyuncs.com/google_containers'
Copy the code
The following figure shows that the startup is successful
Some administrative commands
#state
minikube status
#Stop minikube
minikube stop
#Delete the cluster
minikube delete
Copy the code
#Check the cluster node status
kubectl get nodes
Copy the code
Kubernetes simple feature experience
API YAML format description overview
Before you begin, it is necessary to familiarize yourself with the following formats in the YAML file that describes deployment resources, using nginx-Deployment as an example in the following tests:
apiVersion: apps/v1 # specify the API version
kind: Deployment # Specify the role/type for creating the resource, which can be Deployment or Pod
metadata: Metadata/attributes of the resource
name: nginx-deployment The resource name must be unique in the same namespace
spec: Specify the content of the resource, the expected state, etc
selector:
matchLabels:
app: nginx
replicas: 2 # Desired number of copies
template: Since it is Deployment, here is the definition of Pod
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx # container name
image: Nginx: 1.14.2 # mirror address
ports: Container external port
- containerPort: 80
Copy the code
Commit an Nginx Deployment
First by command
kubectl get deployments
Copy the code
You can see that there are currently no Deployment resources in the cluster
Open a new command window and type the following command to monitor the status of deployments through the watch mechanism:
kubectl get --watch deployments
Copy the code
This window allows you to observe changes to the Deployment resources, but put them aside.
Run the following command:
kubectl apply -f https://kubernetes.io/examples/application/deployment.yaml
Copy the code
Looking at deployment.yaml, you can see that the expectation is for a replica number of 2 with version nginx:1.14.2.
Print the following through the Watch window:
See also deployments with the describe command:
kubectl describe deployment nginx-deployment
Copy the code
Everything is as expected, and the last line is the information for deploymentController, which is also managing the generation of deployments normally.
Upgrade nginx deployment
To upgrade nginx to 1.16.1, modify the image version of the resource YAMl file, as shown below
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
selector:
matchLabels:
app: nginx
replicas: 2
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: Nginx: 1.16.1 Update the version of nginx from 1.14.2 to 1.16.1
ports:
- containerPort: 80
Copy the code
Execute command:
kubectl apply -f https://kubernetes.io/examples/application/deployment-update.yaml
Copy the code
You can see the progression of deployment towards expectations. Describe command to view information:
You can see that the NGINx version has been upgraded to 1.16.1, and deploymentController is scheduled to start new, stop old, start new, stop old.
Expansion nginx deployment
Change the expected number of yamL files from replicas to 4:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
selector:
matchLabels:
app: nginx
replicas: 4 # Update the replicas from 2 to 4
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: Nginx: 1.14.2
ports:
- containerPort: 80
Copy the code
Execute command:
kubectl apply -f https://kubernetes.io/examples/application/deployment-scale.yaml
Copy the code
Describe command to view information:
At the end of the little experience, use kubectl delete deployments nginx-deployment to delete the deployment of the test. Next I will try to build a local Kubernetes cluster environment.