wikiv3:deploy_yaml
Criar Deploy e Serviço através de arquivos YAML
$ kubectl create deploy nginx --image=nginx --dry-run=client -o yaml > deploy.yaml
$ cat deploy.yaml apiVersion: apps/v1 kind: Deployment metadata: creationTimestamp: null labels: app: nginx name: nginx spec: replicas: 1 selector: matchLabels: app: nginx strategy: {} template: metadata: creationTimestamp: null labels: app: nginx spec: containers: - image: nginx name: nginx resources: {} status: {}
$ kubectl apply -f deploy.yaml
$ kubectl get deploy NAME READY UP-TO-DATE AVAILABLE AGE nginx 1/1 1 1 49s
kubectl get pod NAME READY STATUS RESTARTS AGE nginx-85b98978db-tqxcp 1/1 Running 0 109s
$ kubectl get replicaset NAME DESIRED CURRENT READY AGE nginx-85b98978db 1 1 1 2m1s
$ kubectl get all NAME READY STATUS RESTARTS AGE pod/nginx-85b98978db-tqxcp 1/1 Running 0 3m13s NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 3d14h NAME READY UP-TO-DATE AVAILABLE AGE deployment.apps/nginx 1/1 1 1 3m13s NAME DESIRED CURRENT READY AGE replicaset.apps/nginx-85b98978db 1 1 1 3m13s
$ kubectl expose deploy nginx --port=8080 --target-port=80 --dry-run=client -o yaml > service.yaml
$ cat service.yaml apiVersion: v1 kind: Service metadata: creationTimestamp: null labels: app: nginx name: nginx spec: ports: - port: 8080 protocol: TCP targetPort: 80 selector: app: nginx status: loadBalancer: {}
$ kubectl apply -f service.yaml
$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 3d14h nginx ClusterIP 10.111.216.98 <none> 8080/TCP 32s
$ kubectl run -ti client --image=curlimages/curl /bin/sh If you don't see a command prompt, try pressing enter. / $
/ $ curl http://10.111.216.98:8080 <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> html { color-scheme: light dark; } body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html>
/ $ exit Session ended, resume using 'kubectl attach client -c client -i -t' command when the pod is running
$ kubectl get pods NAME READY STATUS RESTARTS AGE client 1/1 Running 1 (99s ago) 6m27s nginx-85b98978db-tqxcp 1/1 Running 0 19m
$ kubectl delete pod client
pod "client" deleted
$ kubectl delete -f deploy.yaml,service.yaml deployment.apps "nginx" deleted service "nginx" deleted
wikiv3/deploy_yaml.txt · Last modified: by 127.0.0.1
