K8S 基础命令尝鲜

启动第一个Pod

# kubectl run nginx --image=nginx:1.14-alpine --replicas=2 --dry-run=true
# kubectl run nginx --image=nginx:1.14-alpine --replicas=2

--dry-run代表测试运行,并不会实际的创建资源

给Pod创建固定访问端点service

# kubectl expose deploy nginx --name=nginx --port=80 --target-port=80 --protocol=TCP
service/nginx exposed

根据固定访问端点地址访问Pods资源

获取固定端点IP

# kubectl get svc
NAME         TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.96.0.1      <none>        443/TCP   2d
nginx        ClusterIP   10.98.152.80   <none>        80/TCP    2d

创建测试应用,通过IP或DNS测试请求资源

# kubectl run -it client --image=busybox -- /bin/sh
If you don't see a command prompt, try pressing enter.
/ # wget -q -O - http://10.98.152.80
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
...
/ # wget -q -O - http://nginx.default.svc.cluster.local.
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
...

results matching ""

    No results matching ""