k8s基础命令
k8s是一个开源的,用于管理云平台中多个主机上的容器化的应用。
快速部署minikub
#!/usr/bin/bash
cd ~;
mkdir bin;
cd bin;
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;
kubectl version --client;
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun;
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://btd5dhca.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
wget https://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/releases/v1.11.0/minikube-linux-amd64;
chmod +x ./minikube-linux-amd64;
sudo mv ./minikube-linux-amd64 /usr/local/bin/minikube;
adduser wzy sudo;
sudo usermod -aG docker $USER && newgrp docker;
minikube start --registry-mirror=https://registry.docker-cn.com --driver=docker;
minikube status
wzy@k8s:~$ minikube status
minikube
type: Control Plane
host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured
wzy@k8s:~$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
minikube Ready master 7m58s v1.18.3
wzy@k8s:~$ kubectl create deployment hello-minikub --image=k8s.gcr.io/echoserver:1.10
deployment.apps/hello-minikub created
wzy@k8s:~$ kubectl get deployments
NAME READY UP-TO-DATE AVAILABLE AGE
hello-minikub 0/1 1 0 16s
wzy@k8s:~$ kubectl expose deployment hello-minikub --type=NodePort --port=8080
service/hello-minikub exposed
wzy@k8s:~$ minikube service hello-minikub --url
http://172.17.0.3:30609
wzy@k8s:~$ kubectl delete services hello-minikub
service "hello-minikub" deleted
wzy@k8s:~$ kubectl delete deployment hello-minikub
deployment.apps "hello-minikub" deleted
wzy@k8s:~$ kubectl get pods
No resources found in default namespace.
controlplane $ kubectl get nodesNAME STATUS ROLES AGE VERSION
controlplane Ready master 8m46s v1.19.0
node01 Ready <none> 8m18s v1.19.0
controlplane $ kubectl status
Error: unknown command "status" for "kubectl"
Run 'kubectl --help' for usage.
controlplane $ kubectl version
Client Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.0", GitCommit:"e19964183377d0ec2052d1f1fa930c4d7575bd50", GitTreeState:"clean", BuildDate:"2020-08-26T14:30:33Z", GoVersion:"go1.15", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.0", GitCommit:"e19964183377d0ec2052d1f1fa930c4d7575bd50", GitTreeState:"clean", BuildDate:"2020-08-26T14:23:04Z", GoVersion:"go1.15", Compiler:"gc", Platform:"linux/amd64"}
controlplane $ kubectl get nodes -o wide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
controlplane Ready master 9m48s v1.19.0 172.17.0.26 <none> Ubuntu 18.04.4 LTS 4.15.0-111-generic docker://19.3.6
node01 Ready <none> 9m20s v1.19.0 172.17.0.28 <none> Ubuntu 18.04.4 LTS 4.15.0-111-generic docker://19.3.6
wzy@k8s:~$ kubectl run nginx --image=nginx
pod/nginx created
wzy@k8s:~$ kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx 0/1 ContainerCreating 0 8s
wzy@k8s:~$ kubectl describe pod nginx
Name: nginx
Namespace: default
Priority: 0
Node: minikube/172.17.0.3
Start Time: Sat, 28 Nov 2020 17:02:34 +0800
Labels: run=nginx
Annotations: <none>
Status: Running
IP: 172.18.0.4
IPs:
IP: 172.18.0.4
Containers:
nginx:
Container ID: docker://7633364a00748b05fa83bb44108b99a65ceba53c84ba1eef05c6b4f9e4f9ffec
Image: nginx
Image ID: docker-pullable://nginx@sha256:6b1daa9462046581ac15be20277a7c75476283f969cb3a61c8725ec38d3b01c3
Port: <none>
Host Port: <none>
State: Running
Started: Sat, 28 Nov 2020 17:03:18 +0800
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-scg6z (ro)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
default-token-scg6z:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-scg6z
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 110s default-scheduler Successfully assigned default/nginx to minikube
Normal Pulling 109s kubelet Pulling image "nginx"
Normal Pulled 67s kubelet Successfully pulled image "nginx"
Normal Created 66s kubelet Created container nginx
Normal Started 66s kubelet Started container nginx