创建第一个K8S应用

操作主机:master

1.手动创建一个应用

1.创建一个测试用的deployment

[root@linux-node1 ~]# kubectl run net-test --image=alpine --replicas=2 sleep 360000

2.查看获取IP情况

[root@linux-node1 ~]# kubectl get pod -o wide
NAME                        READY     STATUS    RESTARTS   AGE       IP          NODE
net-test-74f45db489-gmgv8   1/1       Running   0          1m        10.2.83.2   192.168.56.13
net-test-74f45db489-pr5jc   1/1       Running   0          1m        10.2.59.2   192.168.56.12

3.测试联通性

ping 10.2.83.2

2.利用yaml文件创建k8s应用

1.创建deployment

https://github.com/unixhot/salt-kubernetes/tree/master/addons

kubectl create -f nginx-deployment.yaml

2.查看deployment

kubectl get deployment

3.查看pod

kubectl get pod -o wide

4.测试pod访问

curl --head 10.2.83.17

5.更新deployment

kubectl set image deployment/nginx-deployment nginx=nginx:1.12.2 --record

6.查看更新后的deployment

kubectl get deployment -o wide

7.查看更新历史

kubectl rollout history deployment/nginx-deployment

8.查看具体某一个版本的升级历史

kubelctl rollout history deployment/nginx-deployment --revision=1

9.快速回滚到上一个版本

kubectl rollout undo deployment/nginx-deployment

10.扩容到5个节点

kubectl scale deployment nginx-deployment --replicas 5

11. 查看k8s 内部服务

kubectl  get pod  -n kube-system
kubectl  get all  -n kube-system
kubectl  get service  -n kube-system

如果创建错误,可以查看日志
kubectl get pod -n kube-system # 查看name名
kubectl logs pod/”name“ -n kube-system