19.k8s官方文档

kubectl get - list resources
kubectl describe - show detailed information about a resource
kubectl logs - print the logs from a container in a pod
kubectl exec - execute a command on a container in a pod

2.docker给镜像改名
docker tag 8fa56d18961f k8s.gcr.io/kube-proxy:v1.13.0
docker rmi 10.10.31.205/k8s/kube-proxy:v1.13.0
docker tag d82530ead066 k8s.gcr.io/kube-controller-manager:v1.13.0
docker rmi 10.10.31.205/k8s/kube-controller-manager:v1.13.0
docker tag 9508b7d8008d k8s.gcr.io/kube-scheduler:v1.13.0
docker rmi 10.10.31.205/k8s/kube-scheduler:v1.13.0
docker tag f1ff9b7e3d6e k8s.gcr.io/kube-apiserver:v1.13.0
docker rmi 10.10.31.205/k8s/kube-apiserver:v1.13.0
docker tag f59dcacceff4 k8s.gcr.io/coredns:1.2.6
docker rmi 10.10.31.205/k8s/coredns:1.2.6
docker tag 3cab8e1b9802 k8s.gcr.io/etcd:3.2.24
docker rmi 10.10.31.205/k8s/etcd:3.2.24
docker tag 0dab2435c100 k8s.gcr.io/kubernetes-dashboard-amd64:v1.10.0
docker rmi 10.10.31.205/k8s/kubernetes-dashboard-amd64:v1.10.0
docker tag f0fad859c909 k8s.gcr.io/flannel:v0.10.0-amd64
docker rmi 10.10.31.205/k8s/flannel:v0.10.0-amd64
docker tag da86e6ba6ca1 k8s.gcr.io/pause:3.1
docker rmi 10.10.31.205/k8s/pause:3.1

3.Create a new service
kubectl get pods: look for existing Pods
kubectl get services: list the current Services from our cluster

kubectl expose deployment/kubernetes-bootcamp --type=“NodePort” --port 8080: To create a new service and expose it to external traffic we’ll use the expose command with NodePort as parameter (minikube does not support the LoadBalancer option yet).

kubectl describe services/kubernetes-bootcamp: To find out what port was opened externally (by the NodePort option)

export NODE_PORT= ( k u b e c t l g e t s e r v i c e s / k u b e r n e t e s − b o o t c a m p − o g o − t e m p l a t e = ′ ( i n d e x . s p e c . p o r t s 0 ) . n o d e P o r t ′ ) e c h o N O D E P O R T = (kubectl get services/kubernetes-bootcamp -o go-template='{{(index .spec.ports 0).nodePort}}') echo NODE_PORT= (kubectlgetservices/kubernetesbootcampogotemplate=(index.spec.ports0).nodePort)echoNODEPORT=NODE_PORT: Create an environment variable called NODE_PORT that has the value of the Node port assigned

curl ( m i n i k u b e i p ) : (minikube ip): (minikubeip):NODE_PORT: test that the app is exposed outside of the cluster using curl, the IP of the Node and the externally exposed port

4.Using labels
The Deployment created automatically a label for our Pod. With describe deployment command you can see the name of the label:

kubectl describe deployment

Let’s use this label to query our list of Pods. We’ll use the kubectl get pods command with -l as a parameter, followed by the label values:

kubectl get pods -l run=kubernetes-bootcamp

You can do the same to list the existing services:

kubectl get services -l run=kubernetes-bootcamp

Get the name of the Pod and store it in the POD_NAME environment variable:

export POD_NAME=$(kubectl get pods -o go-template --template ‘{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}’)
echo Name of the Pod: $POD_NAME

To apply a new label we use the label command followed by the object type, object name and the new label:

kubectl label pod $POD_NAME app=v1

This will apply a new label to our Pod (we pinned the application version to the Pod), and we can check it with the describe pod command:

kubectl describe pods $POD_NAME

We see here that the label is attached now to our Pod. And we can query now the list of pods using the new label:

kubectl get pods -l app=v1

And we see the Pod.

  1. Deleting a service
    To delete Services you can use the delete service command. Labels can be used also here:

kubectl delete service -l run=kubernetes-bootcamp

Confirm that the service is gone:

kubectl get services

This confirms that our Service was removed. To confirm that route is not exposed anymore you can curl the previously exposed IP and port:

curl ( m i n i k u b e i p ) : (minikube ip): (minikubeip):NODE_PORT

This proves that the app is not reachable anymore from outside of the cluster. You can confirm that the app is still running with a curl inside the pod:

kubectl exec -ti $POD_NAME curl localhost:8080

We see here that the application is up.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值