kubernetes Single Node Deployment
The Post Created(Updated) On 04/20/2022,Please note the timeliness of the article!
I’ve recently tried to learn K8S, and I think it’s okay! Just for my own project is not necessary, get a docker is good, clusters for small projects deployment is a bit exaggerated. Personally, I found that the official interactive tutorials are quite cool, and it’s still feasible to understand them simply. I’ll get a start-to-finish single-node deployment for everyone to understand, it may be a little messy.
Install
docker installation
- Installing
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
Aliyun
- Note the authorization for non-root users, here is the example of the emperinter user
```shell
sudo usermod -aG docker emperinter
````
## k8s related components installation
- Install minikube
```shell
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube
</code></pre>
<ul>
<li>Install kubectl</li>
</ul>
<pre><code class="language-shell line-numbers">curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release /stable.txt)/bin/linux/amd64/kubectl
chmod +x kubectl
sudo mv . /kubectl /usr/local/bin/kubectl
</code></pre>
<h1>Operation</h1>
<blockquote>
Here is an example of 2 pods, operating with a non-root user
</blockquote>
<h2>Get the image</h2>
<pre><code class="language-shell line-numbers">docker pull wiznote/wizserver
````
## Start environment
- Start minikube
> mount can be found in [Configuring Pod to use PersistentVolume as storage](https://www.emperinter.info/2022/04/18/configure-persistent-volume-storage/)
```shell
minikube start --mount --mount-string="/mnt/data:/app/wiz"
- View
minikube ssh
- Start the dashboard
minikube dashboard
- The dashboard address always changes, so if you want to fix the port, you can use
nohup minikube dashboard >> dashboard.log 2>&1 &
nohup kubectl proxy --port=8080 --address=0.0.0.0 --accept-hosts='^*$' >> proxy.log 2>&1 &
Deployment
Command line deployment
This method is not recommended, there are many things that need to be configured
kubectl create deployment wiz --image=wiznote/wizserver:latest
Configuration file deployment
- Create PVC storage, refer to: [https://www.emperinter.info/2022/04/18/configure-persistent-volume-storage/](https://www.emperinter.info/2022/04/18 /configure-persistent-volume-storage/)
-
Create the configuration file: wiz.yaml
kind: Deployment
apiVersion: apps/v1
metadata:
name: wiz #Deployment name
labels:
app: wiz
spec:
replicas: 2 #Number of target replicas
selector:
matchLabels:
app: wiz
template:
metadata:
labels:
app: wiz
spec:
volumes:
- name: wiz-pv-storage
persistentVolumeClaim:
claimName: wiz-pv-claim #PVC storage name
containers:
- name: wizserver
image: wiznote/wizserver:latest
resources: {}
imagePullPolicy: Always
volumeMounts: #mount points within the container
- mountPath: "/wiz/storage/"
name: wiz-pv-storage #Must have name
ports: #Define ports
- name: container-port #Define pod name
containerPort: 80 #Define pod port
protocol: TCP #define TCP
restartPolicy: Always
terminationGracePeriodSeconds: 30
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 25%
maxSurge: 25%
revisionHistoryLimit: 10
progressDeadlineSeconds: 600
- Deploy with configuration file
kubectl create -f wiz.yaml
Network
Get IP
minikube ip # Get the ip address of minikube
Open network
Simple forwarding
I’m using windwos wsl here, simple forwarding address is:
http://127.0.0.1:8888/
kubectl port-forward deployment/wiz 8888:80
# or
# kubectl port-forward wiz-79b4644f99-447b8 8888:80
# kubectl port-forward service/wiz 8888:80
NodePort port configuration
- The shell runs directly
kubectl expose deployment wiz -- "type=NodePort" --port=8888 --target-port=80 # Expose port 8080, type NodePort (assign a port on each Node as an external access portal)
- You can also create a service
apiVersion: v1
kind: Service
metadata:
name: wiz-service
spec:
type: NodePort
selector:
app: wiz
ports:
- protocol: TCP
port: 8888
targetPort: 80
kubectl create -f wiz-service.yaml
View pod running port
kubectl get services/wiz -o go-template='{{(index .spec.ports 0).nodePort}}'
test
wiz This pod deployment is a bit problematic and sometimes inaccessible.
curl -I minikubeIP:
Other
Change the number of pods
kubectl scale deployments/wiz --replicas=8
View resources
- View all
kuectl get all
- View deployments
kubectl get deployment
- View pod
kubectl get pods
enter pods
kubectl exec -it wiz-5c647c8d4f-rq5q8 -- bash
## exit exit
view logs
kubectl logs wiz-5c647c8d4f-rq5q8
Copyright
Unless otherwise noted, all work on this blog is licensed under a Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0) License. Reprinted with permission from -https://blog.emperinter.info/2022/04/20/kubernetes-single-node-deployment