关键词:
# EXECUTE COMMANDS IN POD
# Get output from running 'date' command from pod mypod, using the first container by default
kubectl exec mypod date
# Get output from running 'date' command in ruby-container from pod mypod
kubectl exec mypod -c ruby-container date
# Switch to raw terminal mode, sends stdin to 'bash' in ruby-container from pod mypod
# and sends stdout/stderr from 'bash' back to the client
kubectl exec mypod -c ruby-container -i -t -- bash -il
# List contents of /usr from the first container of pod mypod and sort by modification time.
# If the command you want to execute in the pod has any flags in common (e.g. -i),
# you must use two dashes (--) to separate your command's flags/arguments.
# Also note, do not surround your command and its flags/arguments with quotes
# unless that is how you would execute it normally (i.e., do ls -t /usr, not "ls -t /usr").
kubectl exec mypod -i -t -- ls -t /usr
# Get output from running 'date' command from the first pod of the deployment mydeployment, using the first container by default
kubectl exec deploy/mydeployment date
# Get output from running 'date' command from the first pod of the service myservice, using the first container by default
kubectl exec svc/myservice date
# UPLOAD & DOWNLOAD CONTENT POD
kubectl cp ./uploads.tgz rumboaloeste/rumboaloeste-wordpress-7cf556f48d-4w697:/var/www/html/wp-content/uploads
# Requires that the 'tar' binary is present in your container
# image. If 'tar' is not present, 'kubectl cp' will fail.
# Copy /tmp/foo_dir local directory to /tmp/bar_dir in a remote pod in the default namespace
kubectl cp /tmp/foo_dir <some-pod>:/tmp/bar_dir
# Copy /tmp/foo local file to /tmp/bar in a remote pod in a specific container
kubectl cp /tmp/foo <some-pod>:/tmp/bar -c <specific-container>
# Copy /tmp/foo local file to /tmp/bar in a remote pod in namespace <some-namespace>
kubectl cp /tmp/foo <some-namespace>/<some-pod>:/tmp/bar
# Copy /tmp/foo from a remote pod to /tmp/bar locally
kubectl cp <some-namespace>/<some-pod>:/tmp/foo /tmp/bar
#Installation and Setting Parameters:
yum install git # Install git
git config --global user.name "<user_name>" # Git global conf
git config --global user.email "<email>" # Git global conf
git config --global system.name "server1.example.com" # Git global conf
git config --global core.editor vim # Set editor to be vim
git config --global core.page 'more' # Git global conf
git config --global core.excludefile ~/.gitignore_global # Ignore files - add lists of the files to be excluded
git config --list
#Basics_Repository:
#[1] Example- Basic git repo work flow
mkdir -p local_repo ; cd local_repo
git init
echo "Hello World" >> hello_world.txt
git add hello_world.txt
git commit -m "Hello World Commit"
git status
#[2] Example - Ignore by .gitignore
mkdir -p local_repo1 ; cd local_repo1
git init
echo "*.conf" >> .gitignore # Ignore all the files with "*.conf"
echo ".gitignore" >> .gitignore
cp /etc/* .
git add <add_individaully> # git add * will not work for this case
git commit
git status
#[2.1] Delete files and folders and commit changes to repo
git checkout infra2 # change to infra2 branch
rm -f Folder1/ Folder2/FolderZ/ file.txt
git add -u :/ # indicate delete files & folders on repo
git commit -m "clean: Delete PRE2 and test files" # save and comment thi step
git push -u origin infra2 # upload changes
#[2.2] Set previous commit from "master" branch to Undo changes whitout commit
git status
git fetch --all
git reset --hard origin/master
git pull
git status
# 2.3 git merge
git checkout master
git merge hotfix
#[3] Example - Bad Example Cloning Local Repo
mkdir -p local_repo_original
cd local_repo_original/
git init
echo ".gitignore" >> .gitignore
echo "*.conf" >> .gitignore
cp /etc/* .
for i in `ls * | grep -v conf `; do git add $i; done
git commit -m "This is a simple commit"
git status
cp -rf local_repo_original/ local_repo_clone_01 # Synchronization with master branch or original repo will not be possible
cd local_repo_clone_01/
git status
#[4] Example - Cloning Local Repo
mkdir -p local_repo_original
cd local_repo_original/
git init
echo ".gitignore" >> .gitignore
echo "*.conf" >> .gitignore
cp /etc/* .
for i in `ls * | grep -v conf `; do git add $i; done
git commit -m "This is a simple commit"
git status
git clone local_repo_original/ local_repo_clone/
cd local_repo_clone/
git status
#[5] Example Synchronization of two repo
mkdir -p local_repo_original
cd local_repo_original/
git init
echo ".gitignore" >> .gitignore
echo "*.conf" >> .gitignore
cp /etc/* .
for i in `ls * | grep -v conf `; do git add $i; done
git commit -m "This is a simple commit"
git status
git clone local_repo_original/ local_repo_clone/
cd local_repo_clone/
touch index.html
echo "Hello World Website" >> index.html
git add index.html
git commit -m "Index HTML Commit"3
git status
Output: # On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
# (use "git push" to publish your local commits)
cd /root/sandbox/local_repo_original/ # Synchronization process
git pull /root/sandbox/local_repo_clone/
git status
cd /root/sandbox/local_repo_clone/
git config --global push.default matching # warning: push.default is unset;.. If encountered
git push
#[6] Exmaple: Remote Repository Clone and Sync
Git remote repo: server1.example.com
Local repo: station1.example.com
Remote repo: server1.example.com:/sandbox/gitrepo
Local repo: station1.example.com:/sandbox/localRepo
setup bi-directiobnal ssh password less authetication
#From station1.example.com,
git clone root@storage-gitlab-00-ah:/sandbox/gitrepo /sandbox/localRepo
cd /sandbox/localRepo
vim hello_world.sh # Simple bash script
vim hello_world.py # Simple python script
git add hello_world.py
git add hello_world.sh
git commit
git status # Your branch is ahead of 'origin/master' by 1 commit. .. Need to sync with the remote repo
#From server1.example.com,
cd /sandbox/gitrepo
git pull root@storage-gitlab-01-ah:/sandbox/localRepo
git status
#From station1.example.com,
git push
#[7] Example git log
git log -a # All logs
git log -p -2 # Latest two log
git log --stat
git log --pretty=oneline
git log --pretty=format:"%h: %an, %ae, %cn, %cd, - %s" --graph # an = author name; ae = author email; cn = commit name; cd = commit date;
#[8] Example git branching, merging and tag
mkdir -p /sandbox/ansible-development ; cd /sandbox/ansible-development/
git init # Copy some files to /sandbox/ansible-development
echo ".gitignore" >> .gitignore
echo "*.md" >> .gitignore
git add * # Follow example 5
git status # On branch master - nothing to commit, working directory clean
git checkout -b development # Create development branch
git checkout -b quality_testing # Create quality_testing brnach
git checkout -b sandbox # Create sandbox branch
git branch -a # List all branch
git checkout development # Switch to development branch
touch development_test.yaml # Create, add and commit in development branch, then switch to master branch, check whether master branch has the file created in development branch
git add development_test.yaml
git commit -m "Development Branch Commit"
git checkout master
ls -ltr # Check for file created in the development branch
git merge development --no-ff # Git merge, --no-ff = Retain all the commit messages prior to commmit
git tag -a Version-0.1 -m "Ansible Release -0.0.1" # Git tag - Similar like "zfs hold" - Annotatted tag
git tag Version1 # Git non-annotated tag
git tag # Git tag (immutable reference) - annotated & non-annotated
git show
git describe --tags
git branch -d <branch_name> # Delete a branch
#[8] Example pushing chages to remote repository
git push origin master
#[9] Example: diff between branches
git diff --name-status master..development # Diff between master and development branch
#[10] Example: Remote Repo Add
git remote add origin <remote repository>
git push origin master # Pushes the changes in local repository up to the remote repository
Important Files:
/etc/gitconfig # System config
/root/.gitconfig # Global config
#get network ips from network $1
docker network inspect -f 'range .Containersprintln .Name .IPv4Addressend' mibb
lxc sub-commands:
config Change container or server configuration options
console Interact with the container's console device and log
copy Copy containers within or in between LXD instances
delete Delete containers and snapshots
exec Execute commands in containers
file Manage files in containers
image Manipulate container images
info Show container or server information
launch Create and start containers from images
list List the existing containers
move Move containers within or in between LXD instances
network Manage and attach containers to networks
operation List, show and delete background operations
profile Manage container configuration profiles
publish Publish containers as images
remote Manage the list of remote LXD servers
rename Rename a container or snapshot
restart Restart containers
restore Restore containers from snapshots
snapshot Create container snapshots
start Start containers
stop Stop containers
storage Manage storage pools and volumes
#version lxc
lxc -v
#full info lxc
lxc info
#log info container
lxc info --show-log miguel-test
##### IMAGES LXC ######
#list images containers
lxc image list
#list image by column (size,description,fingerprint)
lxc image list -c sdf
lxc image copy ab48da5497de nova102
#alias of image
Lxc image alias [create/rename/delete]
#export images to tar
lxc image export ab48da5497de c7.tar
lxc image import <tarball>|<dir> [<rootfs tarball>|<URL>] [<remote>:] [--public] [--created-at=ISO-8601] [--expires-at=ISO-8601] [--fingerprint=FINGERPRINT] [--alias=ALIAS...] [prop=value]
Import an image tarball (or tarballs) or an image directory into the LXD image store.
Directory import is only available on Linux and must be performed as root.
lxc image copy [<remote>:]<image> <remote>: [--alias=ALIAS...] [--copy-aliases] [--public] [--auto-update]
Copy an image from one LXD daemon to another over the network.
The auto-update flag instructs the server to keep this image up to
date. It requires the source to be an alias and for it to be public.
lxc image delete [<remote>:]<image> [[<remote>:]<image>...]
Delete one or more images from the LXD image store.
lxc image refresh [<remote>:]<image> [[<remote>:]<image>...]
Refresh one or more images from its parent remote.
lxc image export [<remote>:]<image> [target]
Export an image from the LXD image store into a distributable tarball.
#### CONTAINERS LXC #######
# list containers
lxc list
#lxc info container
lxc info [container]
#create new container from other without snapshots
lxc copy mvtv-base miguel-test --container-only
#Move a container between two hosts, renaming it if destination name differs.
lxc move [<remote>:]<source container> [<remote>:][<destination container>] [--container-only]
#Rename a local container.
lxc move <old name> <new name> [--container-only]
#Rename a snapshot.
lxc move <container>/<old snapshot name> <container>/<new snapshot name>
#Manage container configuration profiles
lxc profile list [<remote>:]
List available profiles.
lxc profile show [<remote>:]<profile>
Show details of a profile.
lxc profile create [<remote>:]<profile>
Create a profile.
lxc profile copy [<remote>:]<profile> [<remote>:]<profile>
Copy the profile.
lxc profile get [<remote>:]<profile> <key>
Get profile configuration.
lxc profile set [<remote>:]<profile> <key> <value>
Set profile configuration.
lxc profile unset [<remote>:]<profile> <key>
Unset profile configuration.
lxc profile delete [<remote>:]<profile>
Delete a profile.
lxc profile edit [<remote>:]<profile>
Edit profile, either by launching external editor or reading STDIN.
lxc profile rename [<remote>:]<profile> <new-name>
Rename a profile.
#####Profile assignment#####
lxc profile assign [<remote>:]<container> <profiles>
Replace the current set of profiles for the container by the one provided.
lxc profile add [<remote>:]<container> <profile>
Add a profile to a container
lxc profile remove [<remote>:]<container> <profile>
Remove the profile from a container
#### Device management ####
lxc profile device list [<remote>:]<profile>
List devices in the given profile.
lxc profile device show [<remote>:]<profile>
Show full device details in the given profile.
lxc profile device remove [<remote>:]<profile> <name>
Remove a device from a profile.
lxc profile device get [<remote>:]<profile> <name> <key>
Get a device property.
lxc profile device set [<remote>:]<profile> <name> <key> <value>
Set a device property.
lxc profile device unset [<remote>:]<profile> <name> <key>
Unset a device property.
lxc profile device add [<remote>:]<profile> <device> <type> [key=value...]
Add a profile device, such as a disk or a nic, to the containers using the specified profile.
#Manage Config & files containers
# show config container
lxc config show miguel-test
#Edit config of container
lxc config edit miguel-test
#####Container configuration######
lxc config get [<remote>:][container] <key>
Get container or server configuration key.
lxc config set [<remote>:][container] <key> <value>
Set container or server configuration key.
#LIMITS :CPU - RAM ….
#https://github.com/lxc/lxd/blob/master/doc/containers.md
lab@nova101:~$ lxc config set miguel-test limits.cpu 1
lab@nova101:~$ lxc config set miguel-test limits.memory 512
#order boot on container list
lxc config set miguel-test boot.autostart.priority 1
#Seconds to wait for container to shutdown before it is force stopped
lxc config set miguel-test boot.host_shutdown_timeout 1
lxc config unset [<remote>:][container] <key>
Unset container or server configuration key.
lxc config show [<remote>:][container] [--expanded]
Show container or server configuration.
lxc config edit [<remote>:][container]
Edit configuration, either by launching external editor or reading STDIN.
*Container metadata*
lxc config metadata show [<remote>:][container]
Show the container metadata.yaml content.
lxc config metadata edit [<remote>:][container]
Edit the container metadata.yaml, either by launching external editor or reading STDIN.
*Container templates*
lxc config template list [<remote>:][container]
List the names of template files for a container.
lxc config template show [<remote>:][container] [template]
Show the content of a template file for a container.
lxc config template create [<remote>:][container] [template]
Add an empty template file for a container.
lxc config template edit [<remote>:][container] [template]
Edit the content of a template file for a container, either by launching external editor or reading STDIN.
lxc config template delete [<remote>:][container] [template]
Delete a template file for a container.
*Device management*
lxc config device add [<remote>:]<container> <device> <type> [key=value...]
Add a device to a container.
lxc config device get [<remote>:]<container> <device> <key>
Get a device property.
lxc config device set [<remote>:]<container> <device> <key> <value>
Set a device property.
lxc config device unset [<remote>:]<container> <device> <key>
Unset a device property.
lxc config device list [<remote>:]<container>
List devices for container.
lxc config device list miguel-test
lxc config device show [<remote>:]<container>
Show full device details for container.
lxc config device remove [<remote>:]<container> <name>...
Remove device from container.
*Client trust store management*
lxc config trust list [<remote>:]
List all trusted certs.
lxc config trust add [<remote>:] <certfile.crt>
Add certfile.crt to trusted hosts.
lxc config trust remove [<remote>:] [hostname|fingerprint]
Remove the cert from trusted hosts.
# LXC NETWORK
Manage and attach containers to networks.
lxc network list [<remote>:]
List available networks.
lxc network show [<remote>:]<network>
Show details of a network.
lxc network create [<remote>:]<network> [key=value...]
Create a network.
lxc network get [<remote>:]<network> <key>
Get network configuration.
lxc network set [<remote>:]<network> <key> <value>
Set network configuration.
lxc network unset [<remote>:]<network> <key>
Unset network configuration.
lxc network delete [<remote>:]<network>
Delete a network.
lxc network edit [<remote>:]<network>
Edit network, either by launching external editor or reading STDIN.
lxc network rename [<remote>:]<network> <new-name>
Rename a network.
lxc network attach [<remote>:]<network> <container> [device name] [interface name]
Attach a network interface connecting the network to a specified container.
lxc network attach-profile [<remote>:]<network> <profile> [device name] [interface name]
Attach a network interface connecting the network to a specified profile.
lxc network detach [<remote>:]<network> <container> [device name]
Remove a network interface connecting the network to a specified container.
lxc network detach-profile [<remote>:]<network> <container> [device name]
Remove a network interface connecting the network to a specified profile.
# MANAGE FILES
#Delete files in containers.
lxc file delete [<remote>:]<container>/<path> [[<remote>:]<container>/<path>...]
Manage files in containers.
lxc file pull [-r|--recursive] [<remote>:]<container>/<path> [[<remote>:]<container>/<path>...] <target path>
Pull files from containers.
lxc file push [-r|--recursive] [-p|--create-dirs] [--uid=UID] [--gid=GID] [--mode=MODE] <source path> [<source path>...] [<remote>:]<container>/<path>
Push files into containers.
lxc file delete [<remote>:]<container>/<path> [[<remote>:]<container>/<path>...]
Delete files in containers.
lxc file edit [<remote>:]<container>/<path>
Edit files in containers using the default text editor.
#attach network to containers
lxc network attach shitake-mgmt miguel-test eth0
lxc network attach shitake-be miguel-test eth1
Multiple hosts
The "lxc" command line tool can talk to multiple LXD servers and defaults to talking to the local one.
Remote operations require the following two commands having been run on the remote server:
lxc config set core.https_address "[::]"
lxc config set core.trust_password some-password
# lxc config set core.trust_password N0k1117.
The former tells LXD to bind all addresses on port 8443. The latter sets a trust password to be used by new clients.
Now to talk to that remote LXD, you can simply add it with:
lxc remote add host-a <ip address or DNS>
# lxc remote add nova102 10.95.67.73 --accept-certificate --password=N0k1117.
#montar algún directorio por NFS en un contenedor, tenéis que cargarle la siguiente configuración:
printf 'mount fstype=rpc_pipefs,\nmount fstype=nfs,' | lxc config set rebollon-asfoa-1b raw.apparmor –
lxc config set rebollon-asfoa-1b security.privileged true
真●禁秘技●奥义●终端美化(代码片段)
1概述作为一个程序员,可以没钱,没车,没房,没老婆,没女朋友。但是,一定要有一个漂亮骚气的终端。没错,大骚特骚。说什么大实话。先来看看原生的终端:真漂亮啊。再看看美化过的:这才叫终端嘛。美化过的就是不... 查看详情
「python实用秘技03」导出项目的极简环境依赖(代码片段)
...m/CNFeffery/PythonPracticalSkills❞这是我的系列文章「Python实用秘技」的第3期,本系列立足于笔者日常工作中使用Python积累的心得体会,每一期为大家带来一个3分钟即可学会的简单小技巧。作为系列第3期,我们即将学习的... 查看详情
函数和函数式编程(代码片段)
...对象,函数式编程。这是编程的方法论。面向对象的独门秘技是类,class。面向过程的独门秘技是过程,def。函数式编程的独门秘技是函数,def。过程就是没有返回值的函数。但是在python中,过程会返回none.1deffunc1():2#testing13print(... 查看详情
程序员如何接私活外包的秘技(代码片段)
点击上方关注“终端研发部”设为“星标”,和你一起掌握更多数据库知识在网上看到,似乎接私活也有很多不容易,技术问题本身是个因素,还有很多有技术的人接私活时被骗,或者是合作到最后以失败告... 查看详情