Table of Contents
K8S Management and Operations
Tags: k8s, operation
1. Container Deployments
1.1 Quick steps
kubectl config view kubectl config use-context kubernetes-admin@kubernetes kubectl config current-context kubectl get nodes kubectl apply -f sd-rest-deployment.yaml kubectl create -f service-sd-rest-lb.yaml kubectl get deployments. kubectl describe deployments. service-directory kubectl get service kubectl describe service service-directory-lb curl -v 10.107.178.133:9000 kubectl delete service service-directory-lb kubectl delete deployments service-directory
1.2 Helm
Helm defines app cluster using yaml.
.http://localhost/~dang/wiki/doku.php?id=virtualization:k8s:02_k8s_day0
1.3 Operator
Code in golang, python that run in k8s and manage custom resource lifecycle.
2. K8S debug
2.1 Pods error
Identify pod error
kubectl get pods default k8s-dashboard-kubernetes-dashboard-696b8cc6f8-jdwxz 0/1 ContainerCreating 0 15m
See pod error/status log:
kubectl describe pods pod-name # see status report kubectl logs -p service-directory-7df665dc67-445pg (pod-name) # see crash output from **previous terminated containe**
2.2 Attach to running pod
Get a shell to the running Container, the only one in a pod:
kubectl exec -it pod-name -- /bin/bash
The Pod has two containers named main-app and helper-app. The following command would open a shell to the main-app Container.
kubectl exec -it my-pod --container main-app -- /bin/bash
2.3 Checking out the Running Containers with Containerd
3. Debug with docker
3.1 Attach to the running image
Not using attach b/c it allows only one tty, so:
docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 002af509471f opnfv/compass-db "/sbin/entrypoint.sh" 2 minutes ago Up 2 minutes 3306/tcp condescending_bartik docker exec -it -u root 002af509471f /bin/bash kubectl exec -it service-directory-6b948bd66c-b9qgw -- bash
check running port
ss -lan netstat -ntlp
3.2 See console log
sudo docker logs e537fb5d99f7
3.3 Useful commands
Get ippools
kubectl describe ippools.crd.projectcalico.org default-ipv4-ippool
4. Docker hub
repo name is image name
4.1 Pushing a Docker container image to Docker Hub
To push a repository to the Docker Hub, you must name your local image using your Docker Hub username, and the repository name that you created through Docker Hub on the web.
You can add multiple images to a repository, by adding a specific :<tag> to it (for example docs/base:testing). If it’s not specified, the tag defaults to latest.
You can name your local images either when you build it, using
docker build -t <hub-user>/<repo-name>[:<tag>]
, by re-tagging an existing local image
docker tag <existing-image> <hub-user>/<repo-name>[:<tag>]
, or by using
docker commit <existing-container> <hub-user>/<repo-name>[:<tag>]
to commit changes.
Now you can push this repository to the registry designated by its name or tag.
$ docker login #user: thuydang pass: 1.2. $ docker push <hub-user>/<repo-name>:<tag>
The image is then uploaded and available for use by your teammates and/or the community.